Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mint/http1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ defmodule Mint.HTTP1 do

{:error, conn, reason, responses} ->
conn = internal_close(conn)
{:error, conn, reason, responses}
{:error, conn, reason, Enum.reverse(responses)}
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/mint/http2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ defmodule Mint.HTTP2 do
other
end
catch
:throw, {:mint, conn, error, responses} -> {:error, conn, error, responses}
:throw, {:mint, conn, error, responses} -> {:error, conn, error, Enum.reverse(responses)}
end

def stream(%__MODULE__{}, _message) do
Expand Down Expand Up @@ -1091,7 +1091,7 @@ defmodule Mint.HTTP2 do
{:error, %{conn | state: :closed}, error, _responses = []}
end
catch
:throw, {:mint, conn, error, responses} -> {:error, conn, error, responses}
:throw, {:mint, conn, error, responses} -> {:error, conn, error, Enum.reverse(responses)}
end

def recv(_conn, _byte_count, _timeout) do
Expand Down
13 changes: 12 additions & 1 deletion test/mint/http1/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ defmodule Mint.HTTP1Test do
assert_closed_and_released(conn)
end

test "responses before an error are returned in order", %{conn: conn} do
{:ok, conn, ref} = HTTP1.request(conn, "GET", "/", [], nil)
response = "HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\n\r\n5\r\nhello\r\nXX"

assert {:error, conn, %HTTPError{reason: :invalid_chunk_size}, responses} =
HTTP1.stream(conn, {:tcp, conn.socket, response})

assert [{:status, ^ref, 200}, {:headers, ^ref, _}, {:data, ^ref, "hello"}] = responses
assert_closed_and_released(conn)
end

test "connection: close", %{conn: conn} do
{:ok, conn, ref} = HTTP1.request(conn, "GET", "/", [], nil)
response = "HTTP/1.1 200 OK\r\ncontent-length: 1\r\nconnection: close\r\n\r\nX"
Expand Down Expand Up @@ -572,7 +583,7 @@ defmodule Mint.HTTP1Test do
"1\r\nX\r\n0\r\nfoo: " <> String.duplicate("x", 25) <> "\r\n"

assert {:error, _conn, %HTTPError{reason: {:max_header_list_size_exceeded, 32, 30}},
[{:data, _, "X"}, {:headers, _, _}, {:status, _, 200}]} =
[{:status, _, 200}, {:headers, _, _}, {:data, _, "X"}]} =
HTTP1.stream(conn, {:tcp, conn.socket, response})
end

Expand Down
23 changes: 22 additions & 1 deletion test/mint/http2/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,27 @@ defmodule Mint.HTTP2Test do
assert HTTP2.open?(conn, :read)
end

test "responses before a GOAWAY error are returned in order", %{conn: conn} do
{conn, ref} = open_request(conn)

assert_recv_frames [headers(stream_id: stream_id)]

assert {:error, %HTTP2{}, error, responses} =
stream_frames(conn, [
headers(
stream_id: stream_id,
hbf: server_encode_headers([{":status", "200"}]),
flags: set_flags(:headers, [:end_headers])
),
data(stream_id: stream_id, data: "hello", flags: set_flags(:data, [])),
goaway(last_stream_id: stream_id, error_code: :protocol_error, debug_data: "")
])

assert_http2_error error, {:server_closed_connection, :protocol_error, ""}

assert [{:status, ^ref, 200}, {:headers, ^ref, []}, {:data, ^ref, "hello"}] = responses
end

test "with GOAWAY with :no_error and responses after the GOAWAY frame", %{conn: conn} do
{conn, ref} = open_request(conn)

Expand Down Expand Up @@ -2067,7 +2088,7 @@ defmodule Mint.HTTP2Test do
window_update(stream_id: stream_id, window_size_increment: 1000)
])

assert Enum.reverse(responses) == [
assert responses == [
{:status, ref, 200},
{:headers, ref, []},
{:data, ref, ""},
Expand Down
Loading