From 6103310b7410e0d34f1cd3b424513f82b8b975dc Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Wed, 25 Jun 2014 20:34:55 +0200 Subject: [PATCH] fix($http): don't remove content-type header if data is set by request transform Fixes #7910 --- src/ng/http.js | 2 +- test/ng/httpSpec.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ng/http.js b/src/ng/http.js index ba8fcf58809a..8744e2c87189 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -607,7 +607,7 @@ function $HttpProvider() { var reqData = transformData(config.data, headersGetter(headers), config.transformRequest); // strip content-type if data is undefined - if (isUndefined(config.data)) { + if (isUndefined(reqData)) { forEach(headers, function(value, header) { if (lowercase(header) === 'content-type') { delete headers[header]; diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index fd70337a8a97..8be7ec98db51 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -693,6 +693,22 @@ describe('$http', function() { $httpBackend.flush(); }); + it('should NOT delete Content-Type header if request data/body is set by request transform', function() { + $httpBackend.expect('POST', '/url', {'one' : 'two'}, function(headers) { + return headers['Content-Type'] == 'application/json;charset=utf-8'; + }).respond(''); + + $http({ + url: '/url', + method: 'POST', + transformRequest : function(data) { + data = {'one' : 'two'}; + return data; + } + }); + + $httpBackend.flush(); + }); it('should set the XSRF cookie into a XSRF header', inject(function($browser) { function checkXSRF(secret, header) {