diff --git a/src/ng/http.js b/src/ng/http.js index ed9e6712c89b..9bfe3a6b1978 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -314,12 +314,13 @@ function $HttpProvider() { * The interceptors are service factories that are registered with the $httpProvider by * adding them to the `$httpProvider.responseInterceptors` array. The factory is called and * injected with dependencies (if specified) and returns the interceptor — a function that - * takes a {@link ng.$q promise} and returns the original or a new promise. + * takes a {@link ng.$q promise} and a config object, which is the same object that was + * passed to $http and returns the original or a new promise. * *
* // register the interceptor as a service * $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) { - * return function(promise) { + * return function(promise, config) { * return promise.then(function(response) { * // do something on success * }, function(response) { @@ -541,7 +542,7 @@ function $HttpProvider() { // apply interceptors forEach(responseInterceptors, function(interceptor) { - promise = interceptor(promise); + promise = interceptor(promise, config); }); promise.success = function(fn) { diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index 1473ab1ccc3f..6c2fd24d662d 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -99,6 +99,34 @@ describe('$http', function() { expect(response).toBe('HELLO!'); }); }); + + + it('should pass the http config through to the interceptors', function(){ + var interceptedConfig; + var httpConfig = { + method: 'GET', + url: '/test' + } + module(function($httpProvider){ + $httpProvider.responseInterceptors.push(function(){ + return function(httpPromise, config){ + return httpPromise.then(function(response){ + interceptedConfig = config; + return httpPromise; + }); + }; + }); + }); + inject(function($http, $httpBackend){ + $httpBackend.expect('GET', '/test').respond('hello!'); + debugger; + $http(httpConfig); + expect(interceptedConfig).toBeUndefined(); + + $httpBackend.flush(); + expect(interceptedConfig).toBe(httpConfig); + }); + }); }); });