Skip to content

Commit

Permalink
Treat iolist of empty binaries as empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
pvsr committed Jan 22, 2025
1 parent eca5fbb commit 87f0d7e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/hackney_request.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ perform(Client0, {Method0, Path0, Headers0, Body0}) ->
Size, Boundary, Client0);
<<>> when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
handle_body(Headers2, ReqType0, Body0, Client0);
[] when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
handle_body(Headers2, ReqType0, Body0, Client0);
<<>> ->
{Headers2, ReqType0, Body0, Client0};
[] ->
{Headers2, ReqType0, Body0, Client0};
_ when is_list(Body0) ->
Body1 = iolist_to_binary(Body0),
case Body1 of
<<>> when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
handle_body(Headers2, ReqType0, Body1, Client0);
<<>> ->
{Headers2, ReqType0, Body1, Client0};
_ ->
handle_body(Headers2, ReqType0, Body1, Client0)
end;
_ ->
handle_body(Headers2, ReqType0, Body0, Client0)
end,
Expand Down Expand Up @@ -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
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};
_ when is_binary(Body0) ->
S = erlang:byte_size(Body0),
CT = hackney_headers_new:get_value(
Expand Down

0 comments on commit 87f0d7e

Please sign in to comment.