This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
AngularJS incorrectly(?) strips away "Content-Type" from headers when "data" is undefined originally but is assigned an object by a TransformRequest function. #7910
Closed
Description
Here is the relevant chunk of code:
https://github.com/angular/angular.js/blob/master/src/ng/http.js#L609
Scenario
- add a TransformRequest function that adds a property to
data
. e.g.
$http.defaults.transformRequest.unshift(addingRequestTransformer);
where addingRequestTransformer
is something like
function(reqBody, headersGetter) {
// ...
if (reqBody === undefined) {
reqBody = { 'myProp': 'myVal' };
} else {
reqBody['myProp'] = 'myVal';
}
return reqBody;
};
- make a post request without
data
$http.post("http://my.url");
This request ends up going with Content-Type: text
because of browsers' default behavior because Content-Type
is stripped away by the code referenced above.
This reproes on latest Chrome, FF, IE (as expected)
Looking at the immediate surrounding of the $http code, the intent seems to be to send Content-Type: json
as long as data
is not undefined which makes me think it should be checked after transforms are applied (i.e. checking reqData
instead of config.data
for undefined
).