$http is parsing a request to JSON ignoring the content-type #15897
Description
I'm submitting a ...
- bug report
- feature request
- other (Please do not submit support requests here (see above))
Current behavior:
The transformResponse is being executed based on a text/plain content, instead of the content-type headers, causing errors sometimes.
Expected / new behavior:
The transformResponse has to be called based on the content-type headers.
Minimal reproduction of the problem with instructions:
$http.get is trying parse to json a text/plain response (the content-type header from the server is "text/plain") when the text starts with "[" and ends with "]" characters.
Looking the documentation for baddata it says that it parses the body when the content-type header is application/json, and "the response looks like a valid JSON-stringified object or array".
And when I change the default transformResponse function to:
$http.get('/', { transformResponse: [function (data) { return data; }] })
To do nothing when it's called, the request works.
The $http request ignores the content-type response header and try to parse my response based in the body of the response?
Angular version: 1.6.2
Browser: all
Anything else:
I'm not sure how it detects that the body "looks like" a json to parse it automatically. But if the content-type of the response is "text/plain" it doesn't have to parse it, even if the body is a json object (not my case).