From 62cc85cb078c6c3475512f9c62d9212dbef29823 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Wed, 25 Jun 2014 20:34:55 +0200 Subject: [PATCH] fix(): 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 6c6a317a85c9..716f3a4a0700 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 2d9de210111e..dcda9021ce87 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) {