mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 23:34:42 +00:00
fix($http): allow interceptors to completely override headers
Closes #2770
This commit is contained in:
parent
77c715d7ca
commit
514dc0eb16
2 changed files with 23 additions and 1 deletions
|
|
@ -666,6 +666,7 @@ function $HttpProvider() {
|
||||||
|
|
||||||
|
|
||||||
var serverRequest = function(config) {
|
var serverRequest = function(config) {
|
||||||
|
headers = config.headers;
|
||||||
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest);
|
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest);
|
||||||
|
|
||||||
// strip content-type if data is undefined
|
// strip content-type if data is undefined
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
it('should reject the http promise if an interceptor fails', function() {
|
||||||
var reason = new Error('interceptor failed');
|
var reason = new Error('interceptor failed');
|
||||||
module(function($httpProvider) {
|
module(function($httpProvider) {
|
||||||
|
|
@ -752,7 +773,7 @@ describe('$http', function() {
|
||||||
$httpBackend.expect('POST', '/url2', undefined, function(headers) {
|
$httpBackend.expect('POST', '/url2', undefined, function(headers) {
|
||||||
return !headers.hasOwnProperty('content-type');
|
return !headers.hasOwnProperty('content-type');
|
||||||
}).respond('');
|
}).respond('');
|
||||||
|
|
||||||
$http({url: '/url', method: 'POST'});
|
$http({url: '/url', method: 'POST'});
|
||||||
$http({url: '/url2', method: 'POST', headers: {'content-type': 'Rewritten'}});
|
$http({url: '/url2', method: 'POST', headers: {'content-type': 'Rewritten'}});
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue