module Http_daemon: sig
.. end
Main OCaml HTTP module.
Here you can find two set of functions:
- functions which let you start an HTTP Daemon (start* functions)
- facility functions which let you sent responses back to clients
val send_CRLF : Pervasives.out_channel -> unit
send a CRLF sequence on the given output channel, this is mandatory after
the last header was sent and before start sending the response body
val send_status_line : ?version:Http_types.version ->
code:Http_types.status_code -> Pervasives.out_channel -> unit
send response status line, version is the http version used in response,
either code or status must be given (not both, not none) which represent the
HTTP response code, outchan is the output channel to which send status line
val send_basic_headers : ?version:Http_types.version ->
code:Http_types.status_code -> Pervasives.out_channel -> unit
like send_status_line but additionally will also send "Date" and "Server"
standard headers
val send_header : header:string -> value:string -> Pervasives.out_channel -> unit
send an HTTP header on outchan
val send_headers : headers:(string * string) list -> Pervasives.out_channel -> unit
as send_header, but for a list of pairs <header, value>
val send_file : src:Http_types.file_source -> Pervasives.out_channel -> unit
send a file through an out_channel
val respond : ?body:string ->
?headers:(string * string) list ->
?version:Http_types.version ->
?code:Http_types.status_code -> Pervasives.out_channel -> unit
high level response function, respond on outchan sending: basic headers
(including Content-Length computed using 'body' argument), headers probided
via 'headers' argument, body given via 'body' argument. Default response
status is 200, default response HTTP version is Http_common.http_version
val respond_not_found : url:string -> ?version:Http_types.version -> Pervasives.out_channel -> unit
send a 404 (not found) HTTP response
val respond_forbidden : url:string -> ?version:Http_types.version -> Pervasives.out_channel -> unit
send a 403 (forbidden) HTTP response
val respond_redirect : location:string ->
?body:string ->
?version:Http_types.version ->
?code:Http_types.status_code -> Pervasives.out_channel -> unit
send a "redirection" class response, optional body argument contains data
that will be displayed in the body of the response, default response status is
301 (moved permanently), only redirection status are accepted by this
function, other values will raise Failure
val respond_unauthorized : ?version:Http_types.version ->
?realm:string -> Pervasives.out_channel -> unit
respond with a 401 (Unauthorized) response asking for authentication
against given realm (default is the server name)
val respond_error : ?body:string ->
?version:Http_types.version ->
?code:Http_types.status_code -> Pervasives.out_channel -> unit
send an "error" response (i.e. 400 <= status < 600), optional body
argument as per send_redirect, default response status is 400 (bad request),
only error status are accepted by this function, other values will
raise Failure
val respond_file : fname:string -> ?version:Http_types.version -> Pervasives.out_channel -> unit
tipical static pages http daemon behaviour, if requested url is a file,
return it, it it is a directory return a directory listing of it
val respond_with : Http_types.response -> Pervasives.out_channel -> unit
respond using a prebuilt Http_types.response object
val main : Http_types.daemon_spec -> unit
start an HTTP daemon
val default_spec : Http_types.daemon_spec
default daemon specification:
- listen on 0.0.0.0, port 80
- "always ok" callback (return an empty response, response code 200)
- fork a child for each request
- do not change to a root directory (i.e. keep cwd)
- 300 seconds timeout
- ignores exceptions
- no authentication required
- do not automatically close client connections after callback
val daemon_spec : ?address:string ->
?auth:(string * Http_types.auth_info) option ->
?auto_close:bool ->
?callback:(Http_types.request -> Pervasives.out_channel -> unit) ->
?mode:Http_types.daemon_mode ->
?port:int ->
?root_dir:string option ->
?exn_handler:(exn -> Pervasives.out_channel -> unit) option ->
?timeout:int option -> unit -> Http_types.daemon_spec
currified daemon_spec constructor. Each parameter of this function
corresponds to one field of Http_types.daemon_spec and defaults to the
corresponding field of Http_daemon.default_spec
class daemon : ?addr:string -> ?port:int -> unit ->
Http_types.daemon
Object oriented interface to HTTP daemons.
module Trivial: sig
.. end
Trivial static pages HTTP daemon.