package httpaf

  1. Overview
  2. Docs
module Config : sig ... end
type 'handle t
type error = [
  1. | `Bad_request
  2. | `Bad_gateway
  3. | `Internal_server_error
  4. | `Exn of exn
]
type 'handle request_handler = 'handle Reqd.t -> unit
type error_handler = ?request:Request.t -> error -> (Headers.t -> Response.Body.t) -> unit
val create : ?config:Config.t -> ?error_handler:error_handler -> 'handle request_handler -> 'handle t

create ?config ?error_handler ~request_handler creates a connection handler that will service individual requests with request_handler.

val next_read_operation : _ t -> [ `Read of Bigstring.t | `Yield | `Close ]

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

val report_read_result : _ t -> [ `Ok of int | `Eof ] -> unit

report_read_result t result reports the result of the latest read attempt to the connection. report_read_result should be called after a call to next_read_operation that returns a `Read buffer value.

  • `Ok n indicates that the caller successfully received n bytes of input and wrote them into the the read buffer that the caller was provided by next_read_operation.
  • `Eof indicates that the input source will no longer provide any bytes to the read processor.
val yield_reader : _ t -> (unit -> unit) -> unit

yield_reader t continue registers with the connection to call continue when reading should resume. yield_reader should be called after next_read_operation returns a `Yield value.

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 state : _ t -> [ `Running | `Closed_input | `Closed ]

state t is the state of the connection's input and output processors. A connection's input processor may be closed while it's output processor is still running (corresponding to the `Closed_input state), but the output processor can never be closed while in the input processor is open.

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 error_code : _ t -> error option

/

val shutdown_reader : _ t -> unit
val shutdown : _ t -> unit
OCaml

Innovation. Community. Security.