Skip to content
This repository has been 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 opened this issue Jun 19, 2014 · 0 comments

Comments

@dilaver
Copy link

dilaver commented Jun 19, 2014

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).

@Narretz Narretz self-assigned this Jun 20, 2014
@Narretz Narretz added this to the 1.3.0-beta.14 milestone Jun 20, 2014
@Narretz Narretz assigned Narretz and unassigned Narretz Jun 20, 2014
Narretz added a commit to Narretz/angular.js that referenced this issue Jun 25, 2014
Narretz added a commit to Narretz/angular.js that referenced this issue Jun 25, 2014
ckknight pushed a commit to ckknight/angular.js that referenced this issue Jul 16, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.