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

Commit 7027844

Browse files
NarretzCarlo s A. Guillen
authored and
Carlo s A. Guillen
committed
fix($http): don't remove content-type header if data is set by request transform
Fixes #7910
1 parent 16c584e commit 7027844

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ function $HttpProvider() {
679679
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest);
680680

681681
// strip content-type if data is undefined
682-
if (isUndefined(config.data)) {
682+
if (isUndefined(reqData)) {
683683
forEach(headers, function(value, header) {
684684
if (lowercase(header) === 'content-type') {
685685
delete headers[header];

test/ng/httpSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,22 @@ describe('$http', function() {
812812
$httpBackend.flush();
813813
});
814814

815+
it('should NOT delete Content-Type header if request data/body is set by request transform', function() {
816+
$httpBackend.expect('POST', '/url', {'one' : 'two'}, function(headers) {
817+
return headers['Content-Type'] == 'application/json;charset=utf-8';
818+
}).respond('');
819+
820+
$http({
821+
url: '/url',
822+
method: 'POST',
823+
transformRequest : function(data) {
824+
data = {'one' : 'two'};
825+
return data;
826+
}
827+
});
828+
829+
$httpBackend.flush();
830+
});
815831

816832
it('should set the XSRF cookie into a XSRF header', inject(function($browser) {
817833
function checkXSRF(secret, header) {

0 commit comments

Comments
 (0)