Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read data during stream shutdown to ensure we update expected content-length #387

Merged
merged 1 commit into from
Aug 1, 2024
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/bandit/http2/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ defmodule Bandit.HTTP2.Stream do
def ensure_completed(%@for{state: :local_closed} = stream) do
receive do
{:headers, _headers, true} -> do_recv_end_stream(stream, true)
{:data, _data, true} -> do_recv_end_stream(stream, true)
{:data, data, true} -> do_recv_data(stream, data) |> do_recv_end_stream(true)
after
# RFC9113§8.1 - hint the client to stop sending data
0 -> do_send(stream, {:send_rst_stream, Bandit.HTTP2.Errors.no_error()})
Expand Down
27 changes: 27 additions & 0 deletions test/bandit/http2/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,33 @@ defmodule HTTP2PlugTest do
conn |> send_resp(200, <<>>)
end

test "stream is closed without error if plug does not read body", context do
socket = SimpleH2Client.setup_connection(context)

headers = [
{":method", "post"},
{":path", "/no_body_read"},
{":scheme", "https"},
{":authority", "localhost:#{context.port}"},
{"content-length", "3"}
]

SimpleH2Client.send_headers(socket, 1, false, headers)
SimpleH2Client.send_body(socket, 1, true, "ABC")

{:ok, 0, _} = SimpleH2Client.recv_window_update(socket)

assert SimpleH2Client.successful_response?(socket, 1, false)
assert SimpleH2Client.recv_body(socket) == {:ok, 1, true, ""}

Process.sleep(1000)
end

def no_body_read(conn) do
Process.sleep(100)
conn |> send_resp(200, <<>>)
end

test "writing response headers", context do
response = Req.head!(context.req, url: "/header_write_test")

Expand Down