hackney icon indicating copy to clipboard operation
hackney copied to clipboard

feat. Req: ability to suppress default content-type

Open ityonemo opened this issue 4 years ago • 4 comments

I have been mocking a (poorly written) HTTP request by a coworker and after a lot of debugging found that the request was failing to emit a content-type header, it might be nice to suppress the default content-type with an option or by pre-setting it to the atom undefined.

ityonemo avatar Oct 24 '19 21:10 ityonemo

in which case you don't want to send a content-type header ?

benoitc avatar Apr 17 '20 16:04 benoitc

I came across this need too when implementing a call to make this request: https://docs.microsoft.com/en-us/rest/api/storageservices/create-container

It's an HTTP PUT with no body specified, so (I assume) a Content-Type header is not appropriate in this context.

As it happens, MS Azure doesn't seem to care about the default application/octet-stream that is added so I was able to work around easily. I did however end up spending an hour or two of hunting around while I tried to figure out where it was coming from :).

joeapearson avatar Dec 17 '20 15:12 joeapearson

Some context... RFC 2616 states "The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers. [...] if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.", so I guess what hackney could do is suppress content-type, by default, if no body is present in the request (i.e. if content-length =:= 0). (this would prevent an option being required). Some care might also be required for transfer-encoding (I mainly found references to chunked in the source).

paulo-ferraz-oliveira avatar Dec 19 '20 02:12 paulo-ferraz-oliveira

@paulo-ferraz-oliveira thanks. Suppressing content-type as you describe sounds sensible and would work for my particular use case.

joeapearson avatar Dec 22 '20 21:12 joeapearson