Skip to content

Commit

Permalink
refactor: don't store the upgrade handler in Response_state.t (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Nov 29, 2024
1 parent 8ceb388 commit 7de12df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/reqd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ let response { response_state; _ } =
| Waiting -> None
| Streaming (response, _)
| Fixed response
| Upgrade (response, _) -> Some response
| Upgrade response -> Some response

let response_exn { response_state; _ } =
match response_state with
| Waiting -> failwith "httpun.Reqd.response_exn: response has not started"
| Streaming(response, _)
| Fixed response
| Upgrade (response, _) -> response
| Upgrade response -> response

let respond_with_string t response str =
if t.error_code <> `Ok then
Expand Down Expand Up @@ -177,7 +177,7 @@ let unsafe_respond_with_upgrade t headers upgrade_handler =
Writer.write_response t.writer response;
if t.persistent then
t.persistent <- Response.persistent_connection response;
t.response_state <- Upgrade (response, upgrade_handler);
t.response_state <- Upgrade response;
Writer.flush t.writer (fun _reason ->
(* TODO(anmonteiro): probably need to check `Closed here? *)
upgrade_handler ());
Expand Down
2 changes: 1 addition & 1 deletion lib/response_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type t =
| Waiting
| Fixed of Response.t
| Streaming of Response.t * Body.Writer.t
| Upgrade of Response.t * (unit -> unit)
| Upgrade of Response.t

let output_state =
let response_sent_state = function
Expand Down

0 comments on commit 7de12df

Please sign in to comment.