Automatically set content-type: application/json when the body is set to json
complete
Gregory Schier
complete
https://yaak.app/blog/2024.8.0
Gregory Schier
Merged in a post:
content_type自动写入
李程林
选择输入body类型 header里面没有自动生成content_type类型
Gregory Schier
in progress
Should have a fix for this in today's beta release
É
Étienne Lévesque
Gregory Schier Just tried it out, can confirm it works. Thanks!
Gregory Schier
Hmm, the header gets added to the request headers when you set the body type to JSON. How did you create the request (manually, import, etc)?
É
Étienne Lévesque
Gregory Schier I think the request was duplicated from one that was imported from Insomnia v7.
Trying out with new requests, I can confirm the header is indeed set automatically, but it only appears to happen the very first time the body type is changed.
Here are my repro steps:
- Create a new request
- Change the body type to JSON
- Content-Type: application/json gets added
- Change the body type to "No Body"
- Header is removed
- Change the body type to JSON
- Header is not added back
I've also tested the same flow with XML bodies with a similar result (Content-Type: text/xml is set only the first time).
More generally, the header isn't getting set to anything after the first body change. Here's another flow I tested:
- Create a new request
- Change the body type to JSON
- Content-Type: application/json gets added
- Change the body type to XML
- Header is not changed to text/xml
- Change the body type to "No Body"
- Header is removed
- Change the body type to JSON
- Header is not added back