Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make check for connection header values case-insensitive during protocol upgrades #90

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading