package httpaf

  1. Overview
  2. Docs
type t
type error = [
  1. | `Malformed_response of string
  2. | `Invalid_response_body_length of Response.t
  3. | `Exn of exn
]
type response_handler = Response.t -> [ `read ] Body.t -> unit
type error_handler = error -> unit
val request : Request.t -> error_handler:error_handler -> response_handler:response_handler -> [ `write ] Body.t * t
val next_read_operation : t -> [ `Read | `Close ]

next_read_operation t returns a value describing the next operation that the caller should conduct on behalf of the connection.

val read : t -> Bigstring.t -> off:int -> len:int -> int

read t bigstring ~off ~len reads bytes of input from the provided range of bigstring and returns the number of bytes consumed by the connection. read should be called after next_read_operation returns a `Read value and additional input is available for the connection to consume.

val shutdown_reader : t -> unit

shutdown_reader t shuts down the read processor for the connection. All subsequent calls to next_read_operations will return `Close. shutdown_reader should be called after next_read_operation returns a `Read value and there is no further input available for the connection to consume.

val next_write_operation : t -> [ `Write of Bigstring.t IOVec.t list | `Yield | `Close of int ]

next_write_operation t returns a value describing the next operation that the caller should conduct on behalf of the connection.

val report_write_result : t -> [ `Ok of int | `Closed ] -> unit

report_write_result t result reports the result of the latest write attempt to the connection. report_write_result should be called after a call to next_write_operation that returns a `Write buffer value.

  • `Ok n indicates that the caller successfully wrote n bytes of output from the buffer that the caller was provided by next_write_operation.
  • `Closed indicates that the output destination will no longer accept bytes from the write processor.
val yield_writer : t -> (unit -> unit) -> unit

yield_writer t continue registers with the connection to call continue when writing should resume. yield_writer should be called after next_write_operation returns a `Yield value.

val report_exn : t -> exn -> unit

report_exn t exn reports that an error exn has been caught and that it has been attributed to t. Calling this function will swithc t into an error state. Depending on the state t is transitioning from, it may call its error handler before terminating the connection.

val is_closed : t -> bool
OCaml

Innovation. Community. Security.