Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Incorrect handling of response data #265

Open
@jenstroeger

Description

It seems to me that the Content-type of a response is handled incorrectly. For example, if I create a request sending JSON data:

 var options = { 
 ...
 contentType: 'application/json', 
 type: 'json', 
 ...
 };
 var req = reqwest(options);

but the server responds with anything else (e.g. application/pdf) then Reqwest still attempts to decode the response body as JSON. Looking at the code, the culprit seems to be the success() function:

 function success (resp) {
 var type = o['type'] || resp && setType(resp.getResponseHeader('Content-Type')) // resp can be undefined in IE
 ...

here, o['type'] picks the content type of the request, thus prioritizing it over the content type of the response. Further down, this causes the mentioned attempt to decode as JSON what is not JSON.

As a fix, I’d propose to either swap the two sides of the || operator, or to completely remove the o['type'].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /