Wrong content-type used [serious bug]
See original GitHub issueI’ve manually set the content type to application/json
before the axios.post() call.
Yet, when the request is made, it’s picking application/x-www-form-urlencoded
huh?
So I’ve added a transformRequest
function and printed out the headers there:
You can see the JSON object for header, it’s has nested content types inside, for each method. It ignored the content type I’ve manually set.
If I add these code lines then it will work
// unset silly defaults
axios.defaults.headers.post = null
axios.defaults.headers.put = null
but that’s kinda silly and smells. A bug? I’ve read documentation carefully still am in the dark.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
HTTP status code for unaccepted Content-Type in request
For certain resources, my RESTful server only accepts PUT and POST requests with JSON objects as the content body, thus requiring a Content-Type...
Read more >Error “The content type is in use” explained
Recently I have developed a tool to manage content types from a content type hub. Think about renaming content types or changing the...
Read more >How to resolve parse error when HTTP content-type header is ...
The HTTP content-type header is missing in the request or response message. Resolving The Problem. In order to resolve this issue, one can...
Read more >6800 - Chrome doesn't set Content-Type for file upload when ...
I just reproduced this bug on Chrome 7.0.517.41 when trying to upload the attached files. Note that the seq file is plain text,...
Read more >RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
It is a generic, stateless, protocol which can be used for many tasks beyond its ... through extension of its request methods, error...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update: I figured out when it happens.
So if the code tries to
POST
but the body isn’t set, axios resolves to that broken code path that is using the wrong header (picking from axios default rather than the configured options on the instance).I’m having this issue and I’m not using
transformRequest
. MyaxiosInstance
has been created as such:Since
common
is set, I would expect the default to beapplication/json
, but I’m seeing the issue @binarykitchen originally reported, where on some POST calls, theContent-Type
is erroneously set toapplication/x-www-form-urlencoded
.Which POST calls is completely unknown to me. It appears to be random, but this is just code so I’m assuming there is a reproducible error condition.