Empty body should not result in Content-Type header being set #1694
Labels
bug
Something isn't working
good first issue
Straightforward problem, solvable for first-time contributors without deep knowledge of the project
openapi-fetch
Relevant to the openapi-fetch library
PRs welcome
PRs are welcome to solve this issue!
Description
Any HTTP method is free to choose whether it sends a payload or not (GET might be debatable, but that's not important).
When it sends one, it should declare what type it is, by providing
Content-Type
header. When it doesn't send one, it MUST NOT declare the header.The current implementation declares
application/json
for every call, evenGET
without specifying any body:We are currently using a workaround through a middleware:
I know that there are at least two closed issues related to this, but I want to emphasize that this indeed is a bug which makes the library non-compliant with rules of HTTP protocol. I really like the library and I would like to remove this little stain to make it shine even more.
Reproduction
Just fire a POST request against a strict API server, such as Fastify.
and see it respond with 400 Bad Request:
Fastify rightfully complains about the malformed incoming request.
Expected result
There should be no
Content-Type
header present, when we're not sending any body - regardless of the HTTP method.Checklist
The text was updated successfully, but these errors were encountered: