package h2

  1. Overview
  2. Docs

Module H2.ReqdSource

Request Descriptor

Sourcetype t
Sourceval request : t -> Request.t
Sourceval request_body : t -> [ `read ] Body.t
Sourceval response : t -> Response.t option
Sourceval response_exn : t -> Response.t

Responding

The following functions will initiate a response for the corresponding request in t. When the response is fully transmitted to the wire, the stream completes.

From RFC7540§8.1: An HTTP request/response exchange fully consumes a single stream.

Sourceval respond_with_string : t -> Response.t -> string -> unit
Sourceval respond_with_bigstring : t -> Response.t -> Bigstringaf.t -> unit
Sourceval respond_with_streaming : ?flush_headers_immediately:bool -> t -> Response.t -> [ `write ] Body.t
Sourceval push : t -> Request.t -> t

Pushing

HTTP/2 allows a server to pre-emptively send (or "push") responses (along with corresponding "promised" requests) to a client in association with a previous client-initiated request. This can be useful when the server knows the client will need to have those responses available in order to fully process the response to the original request.

push reqd request creates a new (pushed) request descriptor that allows responding to the "promised" request. This function raises an exception if server push is not enabled for the connection.

See RFC7540§8.2 for more details.

Exception Handling

Sourceval report_exn : t -> exn -> unit
Sourceval try_with : t -> (unit -> unit) -> (unit, exn) Result.result