Skip to content

Commit 87f0d7e

Browse files
committed
Treat iolist of empty binaries as empty body
1 parent eca5fbb commit 87f0d7e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/hackney_request.erl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ perform(Client0, {Method0, Path0, Headers0, Body0}) ->
7777
Size, Boundary, Client0);
7878
<<>> when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
7979
handle_body(Headers2, ReqType0, Body0, Client0);
80-
[] when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
81-
handle_body(Headers2, ReqType0, Body0, Client0);
8280
<<>> ->
8381
{Headers2, ReqType0, Body0, Client0};
84-
[] ->
85-
{Headers2, ReqType0, Body0, Client0};
82+
_ when is_list(Body0) ->
83+
Body1 = iolist_to_binary(Body0),
84+
case Body1 of
85+
<<>> when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
86+
handle_body(Headers2, ReqType0, Body1, Client0);
87+
<<>> ->
88+
{Headers2, ReqType0, Body1, Client0};
89+
_ ->
90+
handle_body(Headers2, ReqType0, Body1, Client0)
91+
end;
8692
_ ->
8793
handle_body(Headers2, ReqType0, Body0, Client0)
8894
end,
@@ -348,13 +354,6 @@ handle_body(Headers, ReqType0, Body0, Client) ->
348354
S = hackney_headers_new:get_value(<<"content-length">>, Headers),
349355
{S, CT, Body0};
350356

351-
_ when is_list(Body0) -> % iolist case
352-
Body1 = iolist_to_binary(Body0),
353-
S = erlang:byte_size(Body1),
354-
CT = hackney_headers_new:get_value(
355-
<<"content-type">>, Headers, <<"application/octet-stream">>
356-
),
357-
{S, CT, Body1};
358357
_ when is_binary(Body0) ->
359358
S = erlang:byte_size(Body0),
360359
CT = hackney_headers_new:get_value(

0 commit comments

Comments
 (0)