Module Webs_unix

Webs Unix tooling.

Sending files

Can be used with connectors that support Unix response connections. See this section of the web service howto.

val etag_of_file : string -> Unix.file_descr -> (string option, string) Stdlib.result

etag_of_file _ fd is an etag for fd. It uses the nginx scheme hex(mtime)-hex(size).

val send_file : ?⁠etag:(string -> Unix.file_descr -> (string option, string) Stdlib.result) -> docroot:string -> Webs.Req.t -> (Webs.Resp.tWebs.Resp.t) Stdlib.result

send_file ~docroot req.

  • An etag is computed or the file via etag which is given the filename and its open file descriptor. etag defaults etag_of_file, if you compute your own respect the entity-tag format.

TODO. Implement the full logic with etags, conditionals and ranges.

Connection listeners

type listener = [
| `Host of string * int

Bind a socket on given hostname and port.

| `Sockaddr of Unix.sockaddr

Bind a socket on given address.

| `Fd of Unix.file_descr

Listen on that socket, the client is responsible for closing it.

]

The type for specifying the socket to listen for connections on.

val listener_localhost : listener

listener_localhost is `Host ("localhost", 8000).

val fd_of_listener : listener -> (Unix.file_descr * bool, string) Stdlib.result

fd_of_listener l is fd, close a file descriptor for the specification l, close is true if the client is in charge of closing it. Unless l was `Fd, fd has close on exec set to true.

val listener_of_string : ?⁠default_port:int -> string -> (listener, string) Stdlib.result

listener_of_string s parses a listen specification from s. The format is ADDR[:PORT] or PATH for a Unix domain socket. default_port is used if no port is specified, defaults to 8000.

val pp_listener : Stdlib.Format.formatter -> listener -> unit

pp_listener formats an unspecified representation of listen values.

Connections

type Webs.Resp.connection += Fd of Unix.file_descr

The type for Unix response connections.

module Connector : sig ... end

Tools for writing connectors.

Missing Unix bindings

val realpath : string -> string

realpath p is an absolute pathname for p obtained by resolving all extra / characters, relative path segments and symbolic links. Raises Unix.Unix_error.

Note. This can be removed once a OCaml version with this PR is required.

val sendfile : src:Unix.file_descr -> off:int -> len:int -> Unix.file_descr -> int

sendfile ~src ~off ~len writes len bytes starting at off in src to dst. Raises Unix.Unix_error, you'll also need to do the Unix.EINTR dance. Raises Sys_error if unsupported on the platform.