Module H2.Reqd

Request Descriptor

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

Responding

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

Pushing

An additional note regarding server push:
val push : t -> Request.t -> (t[ `Push_disabled | `Stream_cant_push | `Stream_ids_exhausted ]) Stdlib.result

push reqd request creates a new ("pushed") request descriptor that allows responding to the "promised" request. As per the HTTP/2 specification, request must be cacheable, safe, and must not include a request body (see RFC7540§8.2 for more details). Note: h2 will not validate request against these assumptions.

This function returns Error `Push_disabled when the value of SETTINGS_ENABLE_PUSH is set to 0 (see RFC7540§8.2 for more details), Error `Stream_cant_push when trying to initiate a push stream from a stream that has been obtained from pushing, or Error `Stream_ids_exhausted when the connection has exhausted the range of identifiers available for pushed streams and cannot push on that connection anymore.

Exception Handling

val report_exn : t -> exn -> unit
val try_with : t -> (unit -> unit) -> (unit, exn) Stdlib.result