Skip to content

responseType=text but json is parsed #2791

@neg3ntropy

Description

@neg3ntropy

Describe the bug

I want to get a response as string even if that comes as application/json. Parsing the response to an object is not required and not desired as the only thing I have to do with it is rewrite some urls and I am not sure of the content type the server will use.

To Reproduce

Server:

const http = require("http");
const server = http.createServer((req, res) => {
    res.writeHead(200, {"Content-Type": "application/json"});
    res.end("{\"doNotParse\": 1}");
});
server.listen(1234);

Client:

const axios = require("axios");   
axios.request({url: "http://localhost:1234/", responseType: "text"})
     .then(res => console.log("Type of data is %s", typeof res.data));

Outcome:

Type of data is object

Expected behavior
response data should be the string "{\"doNotParse\": 1}", the program would print:

Type of data is string

Environment:

  • Axios 0.19.2
  • Fedora 31
  • Node 12

Additional context/Screenshots
Setting transformResponse: (data) => data appears to do the trick, regardless of responseType.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions