send method

  1. @override
Future<StreamedResponse> send({
  1. Duration? contentTimeout,
})

Sends this request.

This automatically initializes a new BalanceClient and closes that client once the request is complete. If you're planning on making multiple requests to the same server, you should use a single BalanceClient for all of those requests.

If contentTimeout is not null the request will be aborted if it takes longer than the given duration to receive the entire response. If the timeout occurs before any reply is received from the server the returned future will as an error with a TimeoutException. If the timout occurs after the reply has been started but before the entire body has been read the response stream will emit a TimeoutException and close.

Implementation

@override
Future<StreamedResponse> send({Duration? contentTimeout}) async {
  var client = BalanceClient();

  try {
    var response = await client.send(this, contentTimeout: contentTimeout);
    var stream = onDone(response.stream, client.close);
    return StreamedResponse(ByteStream(stream), response.statusCode,
        contentLength: response.contentLength,
        request: response.request,
        headers: response.headers,
        isRedirect: response.isRedirect,
        persistentConnection: response.persistentConnection,
        reasonPhrase: response.reasonPhrase);
  } catch (_) {
    client.close();
    rethrow;
  }
}