send method
Sends an HTTP request and asynchronously returns the response.
Implementation
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
// http.BaseRequest newRequest;
if (!_requestingNewToken) {
await _mayRefreshToken(request.headers);
}
if (request is http.MultipartRequest) {
return _httpClient.send(
http.MultipartRequest(
request.method,
request.url,
)
..headers.addAll(
_getCustomHeaders(request.headers),
)
..fields.addAll(request.fields)
..files.addAll(request.files),
);
} else if (request is http.Request) {
http.Request newRequest = http.Request(
request.method,
request.url,
)..headers.addAll(
_getCustomHeaders(request.headers),
);
String? contentType = newRequest.headers["content-type"];
if (request.body != "") {
newRequest.body = request.body;
} else if (contentType == "application/x-www-form-urlencoded" && request.bodyFields.isNotEmpty) {
newRequest.bodyFields = request.bodyFields;
} else if (request.bodyBytes.isNotEmpty) {
newRequest.bodyBytes = request.bodyBytes;
}
return _httpClient.send(
newRequest,
);
}
return _httpClient.send(request);
}