Up

module Resolver

: sig

Resolve URIs to endpoints

#
type service = {
# name
: string;
# port
: int;
# tls
: bool;
}

Description of a single service. Can be populated from /etc/services with the exception of the tls field, which indicates if the connection is intended to be TLS/SSL-encrypted or not (e.g. for https).

#
module type S = sig

Module type for a [root:resolution] that can map URIs to concrete [root:endp] that stream connections can be established with.

#
type +'a io

Abstract type of the cooperative threading library used, normally defined via the [root:IO] module type

#
type t

State handle for a running resolver

#
type svc

Abstract type for a service entry, which maps a URI scheme into a protocol handler and TCP port

#
type rewrite_fn = svc -> Uri.t -> Conduit.endp io

A rewrite function resolves a service and a URI into a concrete endpoint.

#
type service_fn = string -> svc option io

A service function maps the string (such as http or ftp) from a URI scheme into a service description that includes enough metadata about the service to subsequently resolve it into an [root:endp].

#
val init : ?service:service_fn -> ?rewrites:(string * rewrite_fn) list -> unit -> t

init ?service ?rewrites will initialize the resolver and return a state handler. The service argument should contain the system-specific resolution mechanism for URI schemas.

The rewrites argument can optionally override a subset of the URI domain name with the given rewrite_fn to permit custom resolution rules. For example, a rewrite rule for ".xen" would let the rewrite function resolve hostnames such as "foo.xen" into a shared memory channel for the "foo" virtual machine.

#
val add_rewrite : host:string -> f:rewrite_fn -> t -> unit

add_rewrite ~host f t will add to the t resolver the f rewrite rule for all the domain names that shortest-prefix match host

#
val set_service : f:service_fn -> t -> unit
#
val resolve_uri : ?rewrites:(string * rewrite_fn) list -> uri:Uri.t -> t -> Conduit.endp io

resolve_uri ?rewrites ~uri t will use t to resolve the uri into a concrete endpoint. Any rewrites that are passed in will be overlayed on the existing rules within the t resolver, but not otherwise modify it.

#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
#
val svc_of_sexp : Sexplib.Sexp.t -> svc
#
val sexp_of_svc : svc -> Sexplib.Sexp.t
end
#
module Make : functor (IO : Conduit.IO) -> S with type svc = service and type 'a io = 'a IO.t

Functor to construct a concrete resolver using a Conduit.IO implementation, usually via either Lwt or Async

#
val service_of_sexp : Sexplib.Sexp.t -> service
#
val sexp_of_service : service -> Sexplib.Sexp.t
end