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

Commit c7c363c

Browse files
Narretzrodyhaddad
authored andcommitted
fix($http): don't remove content-type header if data is set by request transform
Fixes #7910
1 parent 2e61446 commit c7c363c

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
@@ -607,7 +607,7 @@ function $HttpProvider() {
607607
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest);
608608

609609
// strip content-type if data is undefined
610-
if (isUndefined(config.data)) {
610+
if (isUndefined(reqData)) {
611611
forEach(headers, function(value, header) {
612612
if (lowercase(header) === 'content-type') {
613613
delete headers[header];

test/ng/httpSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,22 @@ describe('$http', function() {
693693
$httpBackend.flush();
694694
});
695695

696+
it('should NOT delete Content-Type header if request data/body is set by request transform', function() {
697+
$httpBackend.expect('POST', '/url', {'one' : 'two'}, function(headers) {
698+
return headers['Content-Type'] == 'application/json;charset=utf-8';
699+
}).respond('');
700+
701+
$http({
702+
url: '/url',
703+
method: 'POST',
704+
transformRequest : function(data) {
705+
data = {'one' : 'two'};
706+
return data;
707+
}
708+
});
709+
710+
$httpBackend.flush();
711+
});
696712

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

0 commit comments

Comments
 (0)