From 172a40931be5fe47e7732e5ba173895a1d59c5cd Mon Sep 17 00:00:00 2001 From: perek Date: Mon, 13 Jan 2014 22:34:22 -0800 Subject: [PATCH] fix($http) - add ability to remove default headers Fixes #5784 Closes #5785 --- src/ng/http.js | 6 ++---- test/ng/httpSpec.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index 1f2415628712..42051e4a0f1b 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -777,10 +777,6 @@ function $HttpProvider() { defHeaders = extend({}, defHeaders.common, defHeaders[lowercase(config.method)]); - // execute if header value is function - execHeaders(defHeaders); - execHeaders(reqHeaders); - // using for-in instead of forEach to avoid unecessary iteration after header has been found defaultHeadersIteration: for (defHeaderName in defHeaders) { @@ -795,6 +791,8 @@ function $HttpProvider() { reqHeaders[defHeaderName] = defHeaders[defHeaderName]; } + // execute if header value is a function for merged headers + execHeaders(reqHeaders); return reqHeaders; function execHeaders(headers) { diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index e7a472e3839c..a583f13f005d 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -772,6 +772,18 @@ describe('$http', function() { $httpBackend.flush(); }); + it('should delete default headers if custom header function returns null', function () { + + $httpBackend.expect('POST', '/url', 'messageBody', function(headers) { + return !('Accept' in headers); + }).respond(''); + + $http({url: '/url', method: 'POST', data: 'messageBody', headers: { + 'Accept': function() { return null; } + }}); + $httpBackend.flush(); + }); + it('should override default headers with custom in a case insensitive manner', function() { $httpBackend.expect('POST', '/url', 'messageBody', function(headers) { return headers['accept'] == 'Rewritten' &&