Flatten request body to prevent hackney adding unnecessary headers#6
Flatten request body to prevent hackney adding unnecessary headers#6pvsr wants to merge 1 commit into
Conversation
|
Actually, this could possibly be considered a bug in hackney itself. I'll send a PR upstream and see how it turns out. edit: benoitc/hackney#750. It is a bug in hackney imo, albeit an edge case. But this PR is still worth merging to work better with current releases of hackney. |
|
This negatively impacts performance and makes use of the iolist type all overhead rather than a performance optimisation, so it's not a suitable fix I'm afraid. It would need to be only done for bodiless methods. |
|
When we pass in an iolist hackney does the |
|
With an iolist request body we get to this case statement in hackney_request.erl which handles iolists with: _ when is_list(Body0) -> % iolist case
Body1 = iolist_to_binary(Body0),
S = erlang:byte_size(Body1),
CT = hackney_headers_new:get_value(
<<"content-type">>, Headers, <<"application/octet-stream">>
),
{S, CT, Body1};By calling |
|
Hackney performing unnecessary work is not an argument in favour of us also performing unnecessary work.
The code you have linked also matches the empty iolist that we send. |
Fixes #5.
Hackney sees a body of
<<>>as empty and doesn't set any extra headers for it. But it sees[<<>>]as a non-empty body that happens to have a length of zero, so it gets a content type ofapplication/octet-streamand a content length of0(edit: this is intended for POST/PUT requests only). This PR flattens the body into a single binary so that hackney can detect empty bodies correctly.Unfortunately this isn't practical to unit test, but I can confirm that it fixes the 500 errors I saw in #5.