Skip to content

Commit

Permalink
fix: better keepalive logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leostera committed Jan 16, 2024
1 parent 24f6a00 commit a53e0e3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nomad/http1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ let send_close res ?(req = Trail.Request.make "noop") conn state =
let _ = Adapter.send conn req res in
Close state

let should_keep_alive (req : Trail.Request.t) =
match (req.version, Http.Header.get req.headers "connection") with
| _, Some "close" -> false
| _, Some "keep-alive" -> true
| `HTTP_1_1, _ -> true
| _, _ -> false

let internal_server_error = send_close Trail.Response.(internal_server_error ())
let bad_request = send_close Trail.Response.(bad_request ())
let uri_too_long = send_close Trail.Response.(request_uri_too_long ())
Expand Down Expand Up @@ -249,14 +256,7 @@ let run_handler state conn req =
| _ -> None
in
let _content_length = Trail.Request.content_length req in
let is_keep_alive =
if state.is_keep_alive then state.is_keep_alive
else
match Http.Header.get req.headers "connection" with
| Some "close" -> false
| Some "keep-alive" -> true
| _ -> true
in
let is_keep_alive = should_keep_alive req in
trace (fun f -> f "connection is keep alive? %b" is_keep_alive);
let state = { state with is_keep_alive } in
(state, req.version, host)
Expand Down

0 comments on commit a53e0e3

Please sign in to comment.