committed by
Peter Bacon Darwin
parent
5db625723b
commit
dc7f625f48
+22
-14
@@ -959,26 +959,25 @@ function $HttpProvider() {
|
||||
config.paramSerializer = isString(config.paramSerializer) ?
|
||||
$injector.get(config.paramSerializer) : config.paramSerializer;
|
||||
|
||||
var chain = [serverRequest, undefined];
|
||||
var promise = initiateOutstandingRequest(config);
|
||||
$browser.$$incOutstandingRequestCount();
|
||||
|
||||
var requestInterceptors = [];
|
||||
var responseInterceptors = [];
|
||||
var promise = $q.when(config);
|
||||
|
||||
// apply interceptors
|
||||
forEach(reversedInterceptors, function(interceptor) {
|
||||
if (interceptor.request || interceptor.requestError) {
|
||||
chain.unshift(interceptor.request, interceptor.requestError);
|
||||
requestInterceptors.unshift(interceptor.request, interceptor.requestError);
|
||||
}
|
||||
if (interceptor.response || interceptor.responseError) {
|
||||
chain.push(interceptor.response, interceptor.responseError);
|
||||
responseInterceptors.push(interceptor.response, interceptor.responseError);
|
||||
}
|
||||
});
|
||||
|
||||
while (chain.length) {
|
||||
var thenFn = chain.shift();
|
||||
var rejectFn = chain.shift();
|
||||
|
||||
promise = promise.then(thenFn, rejectFn);
|
||||
}
|
||||
|
||||
promise = chainInterceptors(promise, requestInterceptors);
|
||||
promise = promise.then(serverRequest);
|
||||
promise = chainInterceptors(promise, responseInterceptors);
|
||||
promise.finally(completeOutstandingRequest);
|
||||
|
||||
if (useLegacyPromise) {
|
||||
@@ -1006,9 +1005,18 @@ function $HttpProvider() {
|
||||
|
||||
return promise;
|
||||
|
||||
function initiateOutstandingRequest(config) {
|
||||
$browser.$$incOutstandingRequestCount();
|
||||
return $q.when(config);
|
||||
|
||||
function chainInterceptors(promise, interceptors) {
|
||||
for (var i = 0, ii = interceptors.length; i < ii;) {
|
||||
var thenFn = interceptors[i++];
|
||||
var rejectFn = interceptors[i++];
|
||||
|
||||
promise = promise.then(thenFn, rejectFn);
|
||||
}
|
||||
|
||||
interceptors.length = 0;
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
function completeOutstandingRequest() {
|
||||
|
||||
Reference in New Issue
Block a user