Webs_websocketWebsockets upgrade support.
References.
The type for websocket keys. These are random 16 bytes encoded in base64 with padding.
val random_key : ?crypto_random:Webs_crypto_random.t -> unit -> keyrandom_key () is a random websocket key sourced from the generator crypto_random (default to Webs_crypto_random.get).
val url_schemes : (Webs.Url.scheme * Webs.Url.Authority.port) listurl_schemes has the list of URL schemes (http, https, ws, wss) and their default ports for handshaking. Can be used with Webs.Url.to_endpoint.
val request_upgrade_of_url :
?key:key ->
?headers:Webs.Http.Headers.t ->
?log:string ->
Webs.Url.t ->
(key * Webs.Http.Request.t, string) Stdlib.resultrequest_upgrade_of_url ~url is a `GET request constructed like Webs.Http.Request.of_url and with headers add_request_upgrade_headers ?key headers added and returns key. The scheme of url must be one of "http", "https", "ws" or "wss".
val accept_upgrade :
key:key ->
Webs.Http.Response.t ->
(unit, string) Stdlib.resultaccept_upgrade ~key response finishes the upgrade request. It checks that:
response is Webs.Http.Status.switching_protocols_101has_websocket_upgrade.sec_webocket_accept header has the right value as per keyAfter this the underlying connection can be used to exchange websocket frames.
val is_request_upgrade : Webs.Http.Request.t -> boolis_request_upgrade request is true iff the headers of request satisfy has_websocket_upgrade.
val upgrade_request :
Webs.Http.Request.t ->
(Webs.Http.Response.t, Webs.Http.Response.t) Stdlib.resultupgrade_request request responds to upgrade request to a websocket.
val has_websocket_upgrade : Webs.Http.Headers.t -> boolhas_websocket_upgrade headers checks that headers:
Webs.Http.Headers.connection header with an "upgrade" value.Webs.Http.Headers.upgrade with a "websocket" value.val accept_header_value_of_key : key -> stringaccept_header_value_of_key k is a value for the sec_websocket_accept header for a key k value of a sec_websocket_key header.
val add_request_upgrade_headers :
?key:key ->
Webs.Http.Headers.t ->
key * Webs.Http.Headers.tadd_request_upgrade_headers ~key headers adds headers for a Webosocket upgrade using key (defaults to random_key) to headers and returns key.
val sec_websocket_accept : Webs.Http.Headers.Name.tval sec_websocket_extensions : Webs.Http.Headers.Name.tval sec_websocket_key : Webs.Http.Headers.Name.tval sec_websocket_protocol : Webs.Http.Headers.Name.tval sec_websocket_version : Webs.Http.Headers.Name.t