Skip to content

Commit a72eff4

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

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/hackney_request.erl

+9-11
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,17 @@ 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+
case iolist_to_binary(Body0) of
84+
<<>> when Method =:= <<"POST">> orelse Method =:= <<"PUT">> ->
85+
handle_body(Headers2, ReqType0, Body0, Client0);
86+
<<>> ->
87+
{Headers2, ReqType0, Body0, Client0};
88+
Body1 ->
89+
handle_body(Headers2, ReqType0, Body1, Client0)
90+
end;
8691
_ ->
8792
handle_body(Headers2, ReqType0, Body0, Client0)
8893
end,
@@ -348,13 +353,6 @@ handle_body(Headers, ReqType0, Body0, Client) ->
348353
S = hackney_headers_new:get_value(<<"content-length">>, Headers),
349354
{S, CT, Body0};
350355

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};
358356
_ when is_binary(Body0) ->
359357
S = erlang:byte_size(Body0),
360358
CT = hackney_headers_new:get_value(

0 commit comments

Comments
 (0)