Module Webs_websocket

Websockets upgrade support.

References.

Keys

type key = string

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 -> key

random_key () is a random websocket key sourced from the generator crypto_random (default to Webs_crypto_random.get).

val accept_header_value_of_key : key -> string

accept_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.

Upgrading

val add_request_upgrade_headers : ?key:key -> Webs.Http.Headers.t -> key * Webs.Http.Headers.t

upgrade_headers ~key headers adds headers for a Webosocket upgrade using key (defaults to random_key) to headers and returns key.

val request_upgrade_of_url : ?key:key -> ?headers:Webs.Http.Headers.t -> ?log:string -> ?version:Webs.Http.Version.t -> Webs.Url.t -> (key * Webs.Http.Request.t, string) Stdlib.result

request_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.

val headers_upgradable : Webs.Http.Headers.t -> bool

upgradable hs is true iff hs has a header Webs.Http.Headers.connection with an "upgrade" value and a header Webs.Http.Headers.upgrade with a "websocket" value.

val request_upgradable : Webs.Http.Request.t -> bool

request_upgradable r is true iff Http.Request.headers r satisfies headers_upgradable.

val upgrade_response : Webs.Http.Request.t -> (Webs.Http.Response.t, Webs.Http.Response.t) Stdlib.result

upgrade_response responds to upgrade the request to a websocket

Headers names

val sec_websocket_accept : Webs.Http.Headers.Name.t
val sec_websocket_extensions : Webs.Http.Headers.Name.t
val sec_websocket_key : Webs.Http.Headers.Name.t
val sec_websocket_protocol : Webs.Http.Headers.Name.t
val sec_websocket_version : Webs.Http.Headers.Name.t