Skip to content

Commit

Permalink
fix(): don't remove content-type header if data is set by request tra…
Browse files Browse the repository at this point in the history
…nsform

Fixes angular#7910
  • Loading branch information
Narretz committed Jun 25, 2014
1 parent 1f6a5a1 commit 62cc85c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 16 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 62cc85c

Please sign in to comment.