valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.94k stars 1.76k forks source link

application/octet-stream header gets added by default in case of a DELETE request without body #1705

Closed blaksucram closed 9 months ago

blaksucram commented 9 months ago

Whenever I send a DELETE request without a Content-Type header and a body fasthttp adds the application/octet-stream Content-Type to the request which then confuses some of the back-ends which we call with that request.

As far as I read the several HTTP docs (mozilla and MSDN) a body should be ignored by the webservers which receive one in the DELETE request. This somehow does not fit the current logic which fasthttp implemented:

The header.go file contains logic which add a default Content-Type header in case of

image

Maybe we can either add the DELETE request to the RequestHeader.ignoreBody method or maybe remove the ignoreBody call from the RequestHeader.AppendBytes function.

image

What do you think?

Thanks in advance Marcus

erikdubbelboer commented 9 months ago

I'm not sure where you got your information but according to RFC9110 and the MDN a DELETE request may have a body. It doesn't say webservers should always ignore it. If you have a backend that gets confused by it I suggest you open an issue with them to fix this.

blaksucram commented 9 months ago

Hello @erikdubbelboer.

Got it thanks!

But imho it does not make sense that the library "magically" makes up a Content-Type header of application/octet-stream in case a DELETE request with no body and no Content-Type header is executed.

erikdubbelboer commented 9 months ago

You need to call ResponseHeader.SetNoDefaultContentType(true) to disable that behavior.

blaksucram commented 9 months ago

Thanks! That helped.