sendRequestAndFetchResponse method

  1. @override
Future<BaseResponse> sendRequestAndFetchResponse(
  1. FinalizedRequest finalizedRequest, {
  2. bool streamResponse = false,
})
inherited

Send the request described in finalizedRequest and fetch the response. If streamResponse is true, the response should be streamed.

This logic is platform-specific and should be implemented by the subclass.

Implementation

@override
Future<BaseResponse> sendRequestAndFetchResponse(
    FinalizedRequest finalizedRequest,
    {bool streamResponse = false}) async {
  _streamResponse = streamResponse == true;
  _sent.complete(finalizedRequest);

  // Since the entire request body has already been sent, the upload
  // progress stream can be "completed" by adding a single progress event.
  RequestProgress progress;
  if (contentLength == null || contentLength == 0) {
    progress = RequestProgress(0, 0);
  } else {
    progress = RequestProgress(contentLength!, contentLength!);
  }
  uploadProgressController.add(progress);

  // Wait until this request is completed. This is either done manually by
  // the test (if it has access to this request), or indirectly through the
  // MockHttp logic.
  return _response.future;
}