Skip to content
Discussion options

You must be logged in to vote

auto-detecting responseType from Content-Type headers is a bad idea because:

  1. servers lie constantly - many APIs return JSON but send text/plain or wrong content types. auto-parsing would break these.

  2. security risk - malicious servers could send harmful content-type headers to trigger unexpected parsing behavior.

  3. unpredictability - explicit is better. if you expect JSON, saying responseType: 'json' makes code clearer and avoids surprises.

  4. error handling mess - what if content-type says JSON but body isnt valid JSON? adds complexity and weird failure modes.

the current explicit approach puts you in control, not the server. you decide how to parse, regardles of what headers claim.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1758 on June 17, 2021 16:59.