Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 514dc0e

Browse files
committed
fix($http): allow interceptors to completely override headers
Closes #2770
1 parent 77c715d commit 514dc0e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/ng/http.js

+1
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ function $HttpProvider() {
666666

667667

668668
var serverRequest = function(config) {
669+
headers = config.headers;
669670
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest);
670671

671672
// strip content-type if data is undefined

test/ng/httpSpec.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,27 @@ describe('$http', function() {
284284
});
285285
});
286286

287+
288+
it('should allow replacement of the headers object', function() {
289+
module(function($httpProvider) {
290+
$httpProvider.interceptors.push(function() {
291+
return {
292+
request: function(config) {
293+
config.headers = {foo: 'intercepted'};
294+
return config;
295+
}
296+
};
297+
});
298+
});
299+
inject(function($http, $httpBackend, $rootScope) {
300+
$httpBackend.expect('GET', '/url', null, function (headers) {
301+
return angular.equals(headers, {foo: 'intercepted'});
302+
}).respond('');
303+
$http.get('/url');
304+
$rootScope.$apply();
305+
});
306+
});
307+
287308
it('should reject the http promise if an interceptor fails', function() {
288309
var reason = new Error('interceptor failed');
289310
module(function($httpProvider) {
@@ -752,7 +773,7 @@ describe('$http', function() {
752773
$httpBackend.expect('POST', '/url2', undefined, function(headers) {
753774
return !headers.hasOwnProperty('content-type');
754775
}).respond('');
755-
776+
756777
$http({url: '/url', method: 'POST'});
757778
$http({url: '/url2', method: 'POST', headers: {'content-type': 'Rewritten'}});
758779
$httpBackend.flush();

0 commit comments

Comments
 (0)