package piaf

  1. Overview
  2. Docs
An HTTP library with HTTP/2 support written entirely in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

piaf-0.1.0.tbz
sha256=00c3bea6d1a8c77dc18bbbbf1f449a78253cf17391ad153751b2e87f71307265
sha512=0f35e88b78ec1f1cd06a972ee69e29a8983b4c07dbc0268cc9764d8df5d9c2402cc3710874f54a111095fb57a08fe582d99d1b7e070e141e260af6ced50172aa

doc/piaf.h2/H2/Reqd/index.html

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 : t -> ?flush_headers_immediately:bool -> Response.t -> [ `write ] Body.t
Sourceval schedule_trailers : t -> Headers.t -> unit

schedule_trailers reqd trailers schedules a list of trailers to be sent before the stream is closed, concluding the HTTP message. Should only be used after respond_with_streaming. Raises Failure if trailers have already been scheduled. See RFC7540§8.1 for more information

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.

An additional note regarding server push:

In HTTP/2, PUSH_PROMISE frames must only be sent in the open or half-closed ("remote") stream states. In practice, this means that calling Reqd.push must happen before the entire response body for the associated client-initiated request has been written to the wire. As such, it is dangerous to start a server pushed response in association with either Reqd.respond_with_string or Reqd.respond_with_bigstring, as the entire body for the response that they produce is sent to the output channel immediately, causing the corresponding stream to enter the closed state.

See RFC7540§8.2 for more details.

Sourceval push : t -> Request.t -> (t, [ `Push_disabled | `Stream_cant_push | `Stream_ids_exhausted ]) 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

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

Innovation. Community. Security.