fix: give the correct code+error if protocol upgrade fails

This commit is contained in:
Simon Cruanes 2024-04-15 15:04:44 -04:00
parent 284d1f7400
commit e5191f0fd7
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -364,7 +364,6 @@ let client_handle_for (self : t) ~client_addr ic oc : unit =
let handle_upgrade ~(middlewares : Head_middleware.t list) req
(module UP : UPGRADE_HANDLER) : unit =
try
Log.debug (fun k -> k "upgrade connection");
let send_resp resp =
@ -372,6 +371,7 @@ let client_handle_for (self : t) ~client_addr ic oc : unit =
Response.Private_.output_ ~bytes:bytes_res oc resp
in
try
(* apply head middlewares *)
let req = List.fold_left Head_middleware.apply' req middlewares in
@ -399,7 +399,9 @@ let client_handle_for (self : t) ~client_addr ic oc : unit =
(* handshake successful, proceed with the upgrade handler *)
UP.handle_connection handshake_st ic oc
with e ->
with
| Bad_req (code, err) -> send_resp @@ Response.make_raw ~code err
| e ->
let bt = Printexc.get_raw_backtrace () in
handle_bad_req req e bt
in