registerAndDecorateRequest method
Registers a request created by this client so that it will be canceled if still incomplete when this client is closed. Also decorates the request by adding headers that are set on this client and setting the withCredentials flag.
Implementation
void registerAndDecorateRequest(BaseRequest request) {
_requests.add(request);
request
..uri = baseUri
..headers = _headers
..timeoutThreshold = timeoutThreshold;
if (withCredentials == true) {
request.withCredentials = true;
}
request.autoRetry
..backOff = autoRetry.backOff
..enabled = autoRetry.enabled
..forHttpMethods = autoRetry.forHttpMethods
..forStatusCodes = autoRetry.forStatusCodes
..forTimeouts = autoRetry.forTimeouts
..maxRetries = autoRetry.maxRetries
..test = autoRetry.test;
if (_requestPathway.hasInterceptors) {
request.requestInterceptor = (request) async {
await _requestPathway.process(RequestPayload(request));
};
}
if (_responsePathway.hasInterceptors) {
request.responseInterceptor = (request, response, [exception]) async {
final payload = ResponsePayload(request, response, exception);
return (await _responsePathway.process(payload)).response;
};
}
request.done.then((_) {
_requests.remove(request);
});
}