package shuttle_http

  1. Overview
  2. Docs
module Address : sig ... end
module Ssl : sig ... end
type t

HTTP/1.1 client that supports keep-alives. A client entity can be created once with an address and re-used for multiple requests. The client is closed either when a user explicitly closes it, or if there is an exception when performing a HTTP request using the client.

It is the responsiblity of the user to check that a http call raised an exception and avoid using a connection once an exception is seen in a call.

val sexp_of_t : t -> Sexplib0.Sexp.t
val create : ?interrupt:unit Async.Deferred.t -> ?connect_timeout:Core.Time.Span.t -> ?ssl:Ssl.t -> Address.t -> t Async.Deferred.Or_error.t

Initiate a TCP connection targeting the user provided Address and perform SSL handshake if needed. If an interrup deferred is provided the underlying socket is closed when it resolves. If address is a host + port pair the client will automatically populate the Host HTTP header for outgoing calls, and ensure that SNI and hostname validation is configured if using an SSL connection.

exception Remote_connection_closed

Remote_connection_closed is raised if attempting if an EOF is reached before the full response has been read.

exception Request_aborted

Request_aborted is raised if attempting to enqueue a request within a closed http client.

call Attempts to perform a HTTP request using the user provided client. If the response contains a "Connection: close" header or if there's an exception when performing the call the client will be closed and should not be used for any future calls. If performing multiple calls on a client, users should ensure to only wait on a response promise if all previous responses have been fully read.

val is_closed : t -> bool

is_closed returns if the client has been closed.

val closed : t -> unit Async.Deferred.t

closed returns a deferred that's resolved when the http client is closed.

val close : t -> unit Async.Deferred.t

close initiates shutdown for an http client. Any request that's currently in-flight will be attempt to run, and any pending requests will fail with exception.

module Oneshot : sig ... end
module Persistent : sig ... end

Persistent clients, not to be confused with HTTP/1.1 persistent connections are durable clients that maintain a connection to a service and eagerly and repeatedly reconnect if the underlying socket connection is lost.