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

Commit

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

Fixes #7910
  • Loading branch information
Narretz authored and Carlo s A. Guillen committed Jun 30, 2014
1 parent 16c584e commit 7027844
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 @@ -679,7 +679,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 @@ -812,6 +812,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 7027844

Please sign in to comment.