Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat iolist of empty binaries as empty body #750

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pvsr
Copy link

@pvsr pvsr commented Jan 22, 2025

Normally when the request body is empty, handle_body is only called for POST and PUT requests, since other methods shouldn't have Content-Type and Content-Length headers for empty bodies. But one case is missed in the empty body detection, an iolist containing empty binaries. The gleam hackney wrapper represents empty bodies as [<<>>], triggering this bug and causing gleam-lang/hackney#5.

This PR expands the empty body detection to check if the result of iolist_to_binary is empty.

@pvsr pvsr marked this pull request as draft January 22, 2025 05:24
@pvsr pvsr force-pushed the empty-req-body-detection branch from a72eff4 to 37cef62 Compare January 22, 2025 05:26
@pvsr pvsr force-pushed the empty-req-body-detection branch from 37cef62 to 87f0d7e Compare January 22, 2025 05:29
@@ -348,13 +354,6 @@ handle_body(Headers, ReqType0, Body0, Client) ->
S = hackney_headers_new:get_value(<<"content-length">>, Headers),
{S, CT, Body0};

_ when is_list(Body0) -> % iolist case
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is now handled before calling handle_body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants