Skip to content

Commit

Permalink
fix: make check for 'Connection: Upgrade' header case-insensitive
Browse files Browse the repository at this point in the history
Some clients send lowercase 'upgrade' as value (matching typical keep-alive behaviour)
  • Loading branch information
sam-tombury authored and c-cube committed Nov 7, 2024
1 parent d38eb85 commit b80c5f9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ let find_map f l =
in
aux f l
let string_as_list_contains_ (s : string) (sub : string) : bool =
let header_list_contains_ (s : string) (name : string) : bool =
let name' = String.lowercase_ascii name in
let fragments = String.split_on_char ',' s in
List.exists (fun fragment -> String.trim fragment = sub) fragments
List.exists (fun fragment ->
String.lowercase_ascii (String.trim fragment) = name') fragments
(* handle client on [ic] and [oc] *)
let client_handle_for (self : t) ~client_addr ic oc : unit =
Expand Down Expand Up @@ -379,7 +381,7 @@ let client_handle_for (self : t) ~client_addr ic oc : unit =
(* check headers *)
(match Request.get_header req "connection" with
| Some str when string_as_list_contains_ str "Upgrade" -> ()
| Some str when header_list_contains_ str "Upgrade" -> ()
| _ -> bad_reqf 426 "connection header must contain 'Upgrade'");
(match Request.get_header req "upgrade" with
| Some u when u = UP.name -> ()
Expand Down

0 comments on commit b80c5f9

Please sign in to comment.