Up

module S

: sig

Module type signatures for Cohttp components

#
module type IO = sig

The IO module defines the blocking interface for reading and writing to Cohttp streams

#
type +'a t

'a t represents a blocking monad state

#
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

a >>= b will pass the result of a to the b function. This is a monadic bind.

#
val return : 'a -> 'a t

return a will construct a constant IO value.

#
type ic

ic represents an input channel

#
type oc

oc represents an output channel

#
type conn

conn represents the underlying network flow

#
val iter : ('a -> unit t) -> 'a list -> unit t

iter f l will perform a blocking iteration using f over the l list. The result is determined after all the iterating threads have completed in serial.

#
val read_line : ic -> string option t

read_line ic will read a single line terminated by CR or CRLF from the input channel ic. It returns None if EOF or other error condition is reached.

#
val read : ic -> int -> string t

read ic len will block until a maximum of len characters are read from the input channel ic. It returns an empty string if EOF or some other error condition occurs on the input channel, and can also fewer than len if input buffering is not sufficient to satisfy the request.

#
val read_exactly : ic -> int -> string option t

read_exactly ic len will block until exactly len characters are read from the input channel ic. If EOF or some other error condition is reached, then None is returned.

#
val write : oc -> string -> unit t

write oc s will block until the complete s string is written to the output channel oc.

#
val flush : oc -> unit t

flush oc will return when all previously buffered content from calling write have been written to the output channel oc.

end
#
module type Http_io = sig
#
type t
#
type reader
#
type writer
#
module IO : IO
#
val read : IO.ic -> [
| `Eof
| `Invalid of string
| `Ok of t
] IO.t
#
val has_body : t -> [
| `No
| `Unknown
| `Yes
]
#
val make_body_reader : t -> IO.ic -> reader
#
val read_body_chunk : reader -> Transfer.chunk IO.t
#
val is_form : t -> bool
#
val read_form : t -> IO.ic -> (string * string list) list IO.t
#
val write_header : t -> IO.oc -> unit IO.t
#
val make_body_writer : ?flush:bool -> t -> IO.oc -> writer
#
val write_body : writer -> string -> unit IO.t
#
val write : ?flush:bool -> (writer -> unit IO.t) -> t -> IO.oc -> unit IO.t
end
#
module type Request = sig
#
type t = {
# mutable headers
: Header.t;(*HTTP request headers*)
# mutable meth
: Code.meth;(*HTTP request method*)
# mutable uri
: Uri.t;(*Full HTTP request uri*)
# mutable version
: Code.version;(*HTTP version, usually 1.1*)
# mutable encoding
: Transfer.encoding;(*transfer encoding of this HTTP request*)
}
#
val encoding : t -> Transfer.encoding
#
val set_encoding : t -> Transfer.encoding -> unit
#
val version : t -> Code.version
#
val set_version : t -> Code.version -> unit
#
val uri : t -> Uri.t
#
val set_uri : t -> Uri.t -> unit
#
val meth : t -> Code.meth
#
val set_meth : t -> Code.meth -> unit
#
val headers : t -> Header.t
#
val set_headers : t -> Header.t -> unit
#
module Fields : sig
#
val names : string list
#
val encoding : (t, Transfer.encoding) Fieldslib.Field.t
#
val version : (t, Code.version) Fieldslib.Field.t
#
val uri : (t, Uri.t) Fieldslib.Field.t
#
val meth : (t, Code.meth) Fieldslib.Field.t
#
val headers : (t, Header.t) Fieldslib.Field.t
#
val fold : init:'acc__ -> headers:('acc__ -> (t, Header.t) Fieldslib.Field.t -> 'acc__) -> meth:('acc__ -> (t, Code.meth) Fieldslib.Field.t -> 'acc__) -> uri:('acc__ -> (t, Uri.t) Fieldslib.Field.t -> 'acc__) -> version:('acc__ -> (t, Code.version) Fieldslib.Field.t -> 'acc__) -> encoding:('acc__ -> (t, Transfer.encoding) Fieldslib.Field.t -> 'acc__) -> 'acc__
#
val make_creator : headers:((t, Header.t) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Header.t) * 'compile_acc__) -> meth:((t, Code.meth) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Code.meth) * 'compile_acc__) -> uri:((t, Uri.t) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Uri.t) * 'compile_acc__) -> version:((t, Code.version) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Code.version) * 'compile_acc__) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Transfer.encoding) * 'compile_acc__) -> 'compile_acc__ -> ('input__ -> t) * 'compile_acc__
#
val create : headers:Header.t -> meth:Code.meth -> uri:Uri.t -> version:Code.version -> encoding:Transfer.encoding -> t
#
val map : headers:((t, Header.t) Fieldslib.Field.t -> Header.t) -> meth:((t, Code.meth) Fieldslib.Field.t -> Code.meth) -> uri:((t, Uri.t) Fieldslib.Field.t -> Uri.t) -> version:((t, Code.version) Fieldslib.Field.t -> Code.version) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> Transfer.encoding) -> t
#
val iter : headers:((t, Header.t) Fieldslib.Field.t -> unit) -> meth:((t, Code.meth) Fieldslib.Field.t -> unit) -> uri:((t, Uri.t) Fieldslib.Field.t -> unit) -> version:((t, Code.version) Fieldslib.Field.t -> unit) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> unit) -> unit
#
val for_all : headers:((t, Header.t) Fieldslib.Field.t -> bool) -> meth:((t, Code.meth) Fieldslib.Field.t -> bool) -> uri:((t, Uri.t) Fieldslib.Field.t -> bool) -> version:((t, Code.version) Fieldslib.Field.t -> bool) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> bool) -> bool
#
val exists : headers:((t, Header.t) Fieldslib.Field.t -> bool) -> meth:((t, Code.meth) Fieldslib.Field.t -> bool) -> uri:((t, Uri.t) Fieldslib.Field.t -> bool) -> version:((t, Code.version) Fieldslib.Field.t -> bool) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> bool) -> bool
#
val to_list : headers:((t, Header.t) Fieldslib.Field.t -> 'elem__) -> meth:((t, Code.meth) Fieldslib.Field.t -> 'elem__) -> uri:((t, Uri.t) Fieldslib.Field.t -> 'elem__) -> version:((t, Code.version) Fieldslib.Field.t -> 'elem__) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> 'elem__) -> 'elem__ list
#
val map_poly : ([<
| `Read
| `Set_and_create
], t, 'x0) Fieldslib.Field.user -> 'x0 list
#
module Direct : sig
#
val iter : t -> headers:((t, Header.t) Fieldslib.Field.t -> t -> Header.t -> unit) -> meth:((t, Code.meth) Fieldslib.Field.t -> t -> Code.meth -> unit) -> uri:((t, Uri.t) Fieldslib.Field.t -> t -> Uri.t -> unit) -> version:((t, Code.version) Fieldslib.Field.t -> t -> Code.version -> unit) -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> t -> Transfer.encoding -> unit) -> unit
#
val fold : t -> init:'acc__ -> headers:('acc__ -> (t, Header.t) Fieldslib.Field.t -> t -> Header.t -> 'acc__) -> meth:('acc__ -> (t, Code.meth) Fieldslib.Field.t -> t -> Code.meth -> 'acc__) -> uri:('acc__ -> (t, Uri.t) Fieldslib.Field.t -> t -> Uri.t -> 'acc__) -> version:('acc__ -> (t, Code.version) Fieldslib.Field.t -> t -> Code.version -> 'acc__) -> encoding:('acc__ -> (t, Transfer.encoding) Fieldslib.Field.t -> t -> Transfer.encoding -> 'acc__) -> 'acc__
end
end
#
val make : ?meth:Code.meth -> ?version:Code.version -> ?encoding:Transfer.encoding -> ?headers:Header.t -> Uri.t -> t

Return true whether the connection should be reused

#
val is_keep_alive : t -> bool
#
val make_for_client : ?headers:Header.t -> ?chunked:bool -> ?body_length:int64 -> Code.meth -> Uri.t -> t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
module type Response = sig
#
type t = {
# mutable encoding
: Transfer.encoding;(*Transfer encoding of this HTTP response*)
# mutable headers
: Header.t;(*response HTTP headers*)
# mutable version
: Code.version;(*(** HTTP version, usually 1.1 *)*)
# mutable status
: Code.status_code;(*HTTP status code of the response*)
# mutable flush
: bool;
}
#
val flush : t -> bool
#
val set_flush : t -> bool -> unit
#
val status : t -> Code.status_code
#
val set_status : t -> Code.status_code -> unit
#
val version : t -> Code.version
#
val set_version : t -> Code.version -> unit
#
val headers : t -> Header.t
#
val set_headers : t -> Header.t -> unit
#
val encoding : t -> Transfer.encoding
#
val set_encoding : t -> Transfer.encoding -> unit
#
module Fields : sig
#
val names : string list
#
val flush : (t, bool) Fieldslib.Field.t
#
val status : (t, Code.status_code) Fieldslib.Field.t
#
val version : (t, Code.version) Fieldslib.Field.t
#
val headers : (t, Header.t) Fieldslib.Field.t
#
val encoding : (t, Transfer.encoding) Fieldslib.Field.t
#
val fold : init:'acc__ -> encoding:('acc__ -> (t, Transfer.encoding) Fieldslib.Field.t -> 'acc__) -> headers:('acc__ -> (t, Header.t) Fieldslib.Field.t -> 'acc__) -> version:('acc__ -> (t, Code.version) Fieldslib.Field.t -> 'acc__) -> status:('acc__ -> (t, Code.status_code) Fieldslib.Field.t -> 'acc__) -> flush:('acc__ -> (t, bool) Fieldslib.Field.t -> 'acc__) -> 'acc__
#
val make_creator : encoding:((t, Transfer.encoding) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Transfer.encoding) * 'compile_acc__) -> headers:((t, Header.t) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Header.t) * 'compile_acc__) -> version:((t, Code.version) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Code.version) * 'compile_acc__) -> status:((t, Code.status_code) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> Code.status_code) * 'compile_acc__) -> flush:((t, bool) Fieldslib.Field.t -> 'compile_acc__ -> ('input__ -> bool) * 'compile_acc__) -> 'compile_acc__ -> ('input__ -> t) * 'compile_acc__
#
val create : encoding:Transfer.encoding -> headers:Header.t -> version:Code.version -> status:Code.status_code -> flush:bool -> t
#
val map : encoding:((t, Transfer.encoding) Fieldslib.Field.t -> Transfer.encoding) -> headers:((t, Header.t) Fieldslib.Field.t -> Header.t) -> version:((t, Code.version) Fieldslib.Field.t -> Code.version) -> status:((t, Code.status_code) Fieldslib.Field.t -> Code.status_code) -> flush:((t, bool) Fieldslib.Field.t -> bool) -> t
#
val iter : encoding:((t, Transfer.encoding) Fieldslib.Field.t -> unit) -> headers:((t, Header.t) Fieldslib.Field.t -> unit) -> version:((t, Code.version) Fieldslib.Field.t -> unit) -> status:((t, Code.status_code) Fieldslib.Field.t -> unit) -> flush:((t, bool) Fieldslib.Field.t -> unit) -> unit
#
val for_all : encoding:((t, Transfer.encoding) Fieldslib.Field.t -> bool) -> headers:((t, Header.t) Fieldslib.Field.t -> bool) -> version:((t, Code.version) Fieldslib.Field.t -> bool) -> status:((t, Code.status_code) Fieldslib.Field.t -> bool) -> flush:((t, bool) Fieldslib.Field.t -> bool) -> bool
#
val exists : encoding:((t, Transfer.encoding) Fieldslib.Field.t -> bool) -> headers:((t, Header.t) Fieldslib.Field.t -> bool) -> version:((t, Code.version) Fieldslib.Field.t -> bool) -> status:((t, Code.status_code) Fieldslib.Field.t -> bool) -> flush:((t, bool) Fieldslib.Field.t -> bool) -> bool
#
val to_list : encoding:((t, Transfer.encoding) Fieldslib.Field.t -> 'elem__) -> headers:((t, Header.t) Fieldslib.Field.t -> 'elem__) -> version:((t, Code.version) Fieldslib.Field.t -> 'elem__) -> status:((t, Code.status_code) Fieldslib.Field.t -> 'elem__) -> flush:((t, bool) Fieldslib.Field.t -> 'elem__) -> 'elem__ list
#
val map_poly : ([<
| `Read
| `Set_and_create
], t, 'x0) Fieldslib.Field.user -> 'x0 list
#
module Direct : sig
#
val iter : t -> encoding:((t, Transfer.encoding) Fieldslib.Field.t -> t -> Transfer.encoding -> unit) -> headers:((t, Header.t) Fieldslib.Field.t -> t -> Header.t -> unit) -> version:((t, Code.version) Fieldslib.Field.t -> t -> Code.version -> unit) -> status:((t, Code.status_code) Fieldslib.Field.t -> t -> Code.status_code -> unit) -> flush:((t, bool) Fieldslib.Field.t -> t -> bool -> unit) -> unit
#
val fold : t -> init:'acc__ -> encoding:('acc__ -> (t, Transfer.encoding) Fieldslib.Field.t -> t -> Transfer.encoding -> 'acc__) -> headers:('acc__ -> (t, Header.t) Fieldslib.Field.t -> t -> Header.t -> 'acc__) -> version:('acc__ -> (t, Code.version) Fieldslib.Field.t -> t -> Code.version -> 'acc__) -> status:('acc__ -> (t, Code.status_code) Fieldslib.Field.t -> t -> Code.status_code -> 'acc__) -> flush:('acc__ -> (t, bool) Fieldslib.Field.t -> t -> bool -> 'acc__) -> 'acc__
end
end
#
val make : ?version:Code.version -> ?status:Code.status_code -> ?flush:bool -> ?encoding:Transfer.encoding -> ?headers:Header.t -> unit -> t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
module type Body = sig
#
type t
#
val to_string : t -> string
#
val to_string_list : t -> string list
#
val empty : t
#
val is_empty : t -> bool
#
val of_string : string -> t
#
val of_string_list : string list -> t
#
val map : (string -> string) -> t -> t
#
val transfer_encoding : t -> Transfer.encoding
end
end