switchToRealRequest method
When a mock request is sent, we check to see if there is a mock expectation or handler setup to handle the request. If not, we switch to a real request instance (created from a TransportPlatform instance).
This is handled by the mock request mixin.
Implementation
@override
CommonRequest switchToRealRequest({bool? streamResponse}) {
// There is not a mock expectation or handler set up to handle this request,
// so we fallback to the real TransportPlatform implementation.
final realRequest = createRealRequest()
..autoRetry = autoRetry
..headers = headers
..requestInterceptor = requestInterceptor
..responseInterceptor = responseInterceptor
..timeoutThreshold = timeoutThreshold
..uri = uri
..withCredentials = withCredentials;
// Content-length can be explicitly set on StreamedRequests.
if (this is StreamedRequest && contentLength != null) {
realRequest.contentLength = contentLength;
}
// If the content-type was explicitly set, copy that value over.
if (wasContentTypeSetManually) {
realRequest.contentType = contentType;
}
// Encoding cannot be set on MultipartRequests.
if (this is! MultipartRequest) {
realRequest.encoding = encoding;
}
return realRequest as CommonRequest;
}