]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/ocaml-http/http_daemon.mli
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / ocaml-http / http_daemon.mli
index 975efb894d7cf4cd3bc3f0687187a26a99048aa7..3cc176854560b8c38a5f9be638aae2dd2cf4be11 100644 (file)
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)
 
+(** 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 *)
+
   (** 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_CRLF: out_channel -> unit
@@ -44,9 +49,23 @@ val send_header: header: string -> value: string -> out_channel -> unit
   (** as send_header, but for a list of pairs <header, value> *)
 val send_headers: headers:(string * string) list -> out_channel -> unit
 
+(*
   (** send a file through an out_channel, file can be passed as an in_channel
   (if 'file' is given) or as a file name (if 'name' is given) *)
 val send_file: ?name:string -> ?file:in_channel -> out_channel -> unit
+*)
+  (** send a file through an out_channel *)
+val send_file: src:Http_types.file_source -> 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:
+  ?body:string -> ?headers:(string * string) list ->
+  ?version:Http_types.version -> ?code:int -> ?status:Http_types.status ->
+  out_channel ->
+    unit
 
   (** send a 404 (not found) HTTP response *)
 val respond_not_found:
@@ -59,7 +78,7 @@ val respond_forbidden:
   (** send a "redirection" class response, optional body argument contains data
   that will be displayed in the body of the response, default response status is
   302 (moved permanently), only redirection status are accepted by this
-  function, other values will @raise Failure *)
+  function, other values will raise Failure *)
 val respond_redirect:
   location:string -> ?body:string ->
   ?version: Http_types.version ->
@@ -70,7 +89,7 @@ val respond_redirect:
   (** 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 *)
+  raise Failure *)
 val respond_error:
   ?body:string ->
   ?version: Http_types.version ->
@@ -94,12 +113,15 @@ val respond_with: Http_types.response -> out_channel -> unit
   the HTTP client to which the user can write directly. 'timeout' parameter sets
   a timeout for each request processed by the daemon, if it's set to None,
   daemon waits forever for completed requests (use with care!), default is 5
-  minute. 'fork' parameter (default 'true') sets whether the daemon forks a
-  child for each request or not, if children aren't forked request are server
-  one at a time (backlog is 10) and callbacks live in the same address space of
-  the process invoking 'start' *)
+  minute. 'mode' parameter has 3 possible values: `Single means that all request
+  are handled by the same process, `Fork means that each request is handled by a
+  separate process, `Thread means that each request is handled by a separate
+  thread, default is `Fork; 'root' (mnemonic "document root") is the directory
+  where the daemon chdir before starting up, default is current working
+  directory *)
 val start:
-  ?addr: string -> ?port: int -> ?timeout: int option -> ?fork: bool ->
+  ?addr: string -> ?port: int ->
+  ?timeout: int option -> ?mode: Http_types.daemon_mode -> ?root: string ->
   (string -> (string * string) list -> out_channel -> unit) ->
     unit
 
@@ -107,14 +129,30 @@ val start:
   one is an out_channel as per 'start', but the secondo one is a Request.request
   object *)
 val start':
-  ?addr: string -> ?port: int -> ?timeout: int option -> ?fork: bool ->
+  ?addr: string -> ?port: int ->
+  ?timeout: int option -> ?mode: Http_types.daemon_mode -> ?root: string -> 
   (Http_types.request -> out_channel -> unit) ->
     unit
 
-  (** Trivial static pages HTTP daemon *)
+  (** Object oriented interface to HTTP daemons.
+  @param addr address on which daemon will listen for connections
+  @param port port which daemon will bind
+  see {! Http_types.daemon} *)
+class daemon:
+  ?addr: string -> ?port: int ->
+    unit ->
+      Http_types.daemon
+
+  (** Trivial static pages HTTP daemon.
+  Daemons created using this module will serve directory indexes and files found
+  starting from the working directory *)
 module Trivial :
   sig
+      (** callback function, exposed if you like to use it as a basis to define
+      a more powerful daemon *)
     val callback : string -> 'a -> out_channel -> unit
+
+      (** start the "trivial" HTTP daemon *)
     val start : ?addr:string -> ?port:int -> unit -> unit
   end