Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8346787

Browse files
Narretzrodyhaddad
authored andcommittedJun 30, 2014
fix($http): don't remove content-type header if data is set by request transform
Fixes #7910
1 parent 1d69015 commit 8346787

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎src/ng/http.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 0 deletions
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)
This repository has been archived.