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

Commit

Permalink
fix($http): allow interceptors to completely override headers
Browse files Browse the repository at this point in the history
Closes #2770
  • Loading branch information
IgorMinar committed Jul 13, 2013
1 parent 77c715d commit 514dc0e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ function $HttpProvider() {


var serverRequest = function(config) {
headers = config.headers;
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest);

// strip content-type if data is undefined
Expand Down
23 changes: 22 additions & 1 deletion test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,27 @@ describe('$http', function() {
});
});


it('should allow replacement of the headers object', function() {
module(function($httpProvider) {
$httpProvider.interceptors.push(function() {
return {
request: function(config) {
config.headers = {foo: 'intercepted'};
return config;
}
};
});
});
inject(function($http, $httpBackend, $rootScope) {
$httpBackend.expect('GET', '/url', null, function (headers) {
return angular.equals(headers, {foo: 'intercepted'});
}).respond('');
$http.get('/url');
$rootScope.$apply();
});
});

it('should reject the http promise if an interceptor fails', function() {
var reason = new Error('interceptor failed');
module(function($httpProvider) {
Expand Down Expand Up @@ -752,7 +773,7 @@ describe('$http', function() {
$httpBackend.expect('POST', '/url2', undefined, function(headers) {
return !headers.hasOwnProperty('content-type');
}).respond('');

$http({url: '/url', method: 'POST'});
$http({url: '/url2', method: 'POST', headers: {'content-type': 'Rewritten'}});
$httpBackend.flush();
Expand Down

0 comments on commit 514dc0e

Please sign in to comment.