Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,25 @@ let ws_upgrade :
in
match Body.drain response.body with
| Error #Error.t as err -> err
| Ok () -> Http_impl.upgrade_connection ~sw:t.sw t.conn
| Ok () ->
(* From RFC6455§4.2.2:
* If the server chooses to accept the incoming connection, it MUST
* reply with a valid HTTP response indicating the following.
* 1. A Status-Line with a 101 response code as per RFC 2616
* [RFC2616]. Such a response could look like "HTTP/1.1 101
* Switching Protocols".
* 2. An |Upgrade| header field with value "websocket" as per RFC
* 2616 [RFC2616].
* 3. A |Connection| header field with value "Upgrade". *)
(match
Headers.(
( get response.headers Well_known.connection
, get response.headers Well_known.upgrade
, response.status ))
with
| Some ("Upgrade" | "upgrade"), Some "websocket", `Switching_protocols ->
Http_impl.upgrade_connection ~sw:t.sw t.conn
| _ -> Error (`Msg "WebSocket upgrade request refused"))

module Oneshot = struct
(* Note: we're not sending `Connection: close`:
Expand Down
4 changes: 2 additions & 2 deletions lib/headers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let add_length_related_headers ~version ~body_length headers =
* 0-length response body. *)
(* Don't step over an explicit `content-length` header. *)
match body_length with
| `Fixed n ->
| `Fixed n when not (Int64.equal (Int64.of_string "0") n) ->
add_unless_exists headers Well_known.content_length (Int64.to_string n)
| `Chunked ->
(* From RFC9113§8.2.2:
Expand All @@ -78,7 +78,7 @@ let add_length_related_headers ~version ~body_length headers =
Well_known.Values.chunked)
| `Close_delimited ->
add_unless_exists headers Well_known.connection Well_known.Values.close
| `Error _ | `Unknown -> headers
| `Error _ | `Unknown | _ -> headers

(* TODO: Add user-agent if not defined *)
let canonicalize_headers ~body_length ~host ~version headers =
Expand Down
4 changes: 2 additions & 2 deletions lib/scheme.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type t =

let of_uri uri =
match Uri.scheme uri with
| None | Some "http" -> Ok `HTTP
| Some "https" -> Ok `HTTPS
| None | Some "http" | Some "ws" -> Ok `HTTP
| Some "https" | Some "wss" -> Ok `HTTPS
(* We don't support anything else *)
| Some other -> Error (`Msg (Format.asprintf "Unsupported scheme: %s" other))

Expand Down