Skip to content

Commit 347d7e8

Browse files
committed
Use IO.iodata_to_binary/1
1 parent 852d90e commit 347d7e8

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

lib/mint/http.ex

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -921,26 +921,36 @@ defmodule Mint.HTTP do
921921
}
922922
def recv_response(conn, ref, timeout)
923923
when is_reference(ref) and Util.is_timeout(timeout) do
924-
recv_response([], %{status: nil, headers: [], body: ""}, conn, ref, timeout)
924+
recv_response([], {nil, [], ""}, conn, ref, timeout)
925925
end
926926

927-
defp recv_response([{:status, ref, status} | rest], acc, conn, ref, timeout) do
928-
acc = put_in(acc.status, status)
929-
recv_response(rest, acc, conn, ref, timeout)
927+
defp recv_response(
928+
[{:status, ref, new_status} | rest],
929+
{_status, headers, body},
930+
conn,
931+
ref,
932+
timeout
933+
) do
934+
recv_response(rest, {new_status, headers, body}, conn, ref, timeout)
930935
end
931936

932-
defp recv_response([{:headers, ref, headers} | rest], acc, conn, ref, timeout) do
933-
acc = update_in(acc.headers, &(&1 ++ headers))
934-
recv_response(rest, acc, conn, ref, timeout)
937+
defp recv_response(
938+
[{:headers, ref, new_headers} | rest],
939+
{status, headers, body},
940+
conn,
941+
ref,
942+
timeout
943+
) do
944+
recv_response(rest, {status, headers ++ new_headers, body}, conn, ref, timeout)
935945
end
936946

937-
defp recv_response([{:data, ref, data} | rest], acc, conn, ref, timeout) do
938-
acc = update_in(acc.body, &(&1 <> data))
939-
recv_response(rest, acc, conn, ref, timeout)
947+
defp recv_response([{:data, ref, data} | rest], {status, headers, body}, conn, ref, timeout) do
948+
recv_response(rest, {status, headers, [body, data]}, conn, ref, timeout)
940949
end
941950

942-
defp recv_response([{:done, ref} | _rest], acc, conn, ref, _timeout) do
943-
{:ok, conn, acc}
951+
defp recv_response([{:done, ref} | _rest], {status, headers, body}, conn, ref, _timeout) do
952+
response = %{status: status, headers: headers, body: IO.iodata_to_binary(body)}
953+
{:ok, conn, response}
944954
end
945955

946956
defp recv_response([{:error, ref, error} | _rest], _acc, conn, ref, _timeout) do

0 commit comments

Comments
 (0)