send method
Sends this request.
This automatically initializes a new Client 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 Client for all of those requests.
Implementation
Future<StreamedResponse> send() async {
var client = Client();
try {
var response = await client.send(this);
var stream = onDone(response.stream, client.close);
if (response case BaseResponseWithUrl(:final url)) {
return StreamedResponseV2(ByteStream(stream), response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
url: url,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
} else {
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;
}
}