Skip to content

Commit

Permalink
feat(http/1): handles the case where the declared content length is l…
Browse files Browse the repository at this point in the history
…ess than what is sent
  • Loading branch information
leostera committed Jan 3, 2024
1 parent 20189db commit 3071a81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/bandit/test/bandit/http1/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ defmodule HTTP1RequestTest do
"POST /error_catcher HTTP/1.1\r\nhost: localhost\r\ncontent-length: 3\r\n\r\nABCDE"
)

assert {:ok, "200 OK", _, "excess_body_read"} = SimpleHTTP1Client.recv_reply(client)
assert {:ok, "200 OK", _, "Excess_body_read"} = SimpleHTTP1Client.recv_reply(client)
end

test "reading request body multiple times works as expected", context do
Expand Down
10 changes: 8 additions & 2 deletions test/http_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ module Test : Application.Intf = struct
let[@warning "-8"] (Conn.Error (conn, reason)) =
Conn.read_body conn
in
let body = Format.asprintf "%a" IO.pp_err reason in
let body =
match reason with
| `Excess_body_read -> "Excess_body_read"
| ( `Closed | `Process_down | `Timeout
| `Unix_error _ ) as reason ->
Format.asprintf "%a" IO.pp_err reason
in
conn |> Conn.send_response `OK ~body
| _ ->
let[@warning "-8"] (Conn.Ok (conn, body)) = Conn.read_body conn in
Expand All @@ -165,7 +171,7 @@ module Test : Application.Intf = struct
~transport:
Atacama.Transport.(
tcp
~config:{ receive_timeout = 1_000_000L; send_timeout = 1_000_000L }
~config:{ receive_timeout = 5_000_000L; send_timeout = 5_000_000L }
())
~config:
(Nomad.Config.make ~max_header_count:40 ~max_header_length:5000 ())
Expand Down

0 comments on commit 3071a81

Please sign in to comment.