Skip to content
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
@dilaver

Description

@dilaver

Here is the relevant chunk of code:
https://github.com/angular/angular.js/blob/master/src/ng/http.js#L609

Scenario

  1. 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;
};
  1. 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).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions