Skip to content

Commit

Permalink
Expose body read timeouts as 408 Request Timeout errors (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel authored Aug 1, 2024
1 parent af19424 commit d8056ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/bandit/http1/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ defmodule Bandit.HTTP1.Socket do
end

{:error, :timeout} ->
already_read
request_error!("Body read timeout", :request_timeout)

{:error, reason} ->
request_error!(reason)
Expand Down
9 changes: 4 additions & 5 deletions test/bandit/http1/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -875,17 +875,16 @@ defmodule HTTP1RequestTest do
"POST /short_body HTTP/1.1\r\nhost: localhost\r\ncontent-length: 5\r\n\r\nABC"
)

assert {:ok, "200 OK", _, "OK"} = SimpleHTTP1Client.recv_reply(client)
assert {:ok, "408 Request Timeout", _, ""} = SimpleHTTP1Client.recv_reply(client)
Process.sleep(1100)
end)

assert errors =~ "(Bandit.HTTPError) Unable to read remaining data in request body"
assert errors =~ "(Bandit.HTTPError) Body read timeout"
end

def short_body(conn) do
{:more, "ABC", conn} = Plug.Conn.read_body(conn)
{:more, "", conn} = Plug.Conn.read_body(conn)
send_resp(conn, 200, "OK")
Plug.Conn.read_body(conn)
raise "Shouldn't get here"
end

test "handles the case where the declared content length is less than what is sent",
Expand Down

0 comments on commit d8056ec

Please sign in to comment.