3 OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
5 Copyright (C) <2002> Stefano Zacchiroli <zack@cs.unibo.it>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 (** send a CRLF sequence on the given output channel, this is mandatory after
23 the last header was sent and before start sending the response body *)
24 val send_CRLF: out_channel -> unit
26 (** send response status line, version is the http version used in response,
27 either code or status must be given (not both, not none) which represent the
28 HTTP response code, outchan is the output channel to which send status line *)
30 ?version: Http_types.version -> ?code: int -> ?status: Http_types.status ->
34 (** like send_status_line but additionally will also send "Date" and "Server"
36 val send_basic_headers:
37 ?version: Http_types.version -> ?code: int -> ?status: Http_types.status ->
41 (** send an HTTP header on outchan *)
42 val send_header: header: string -> value: string -> out_channel -> unit
44 (** as send_header, but for a list of pairs <header, value> *)
45 val send_headers: headers:(string * string) list -> out_channel -> unit
47 (** send a file through an out_channel, file can be passed as an in_channel
48 (if 'file' is given) or as a file name (if 'name' is given) *)
49 val send_file: ?name:string -> ?file:in_channel -> out_channel -> unit
51 (** high level response function, respond on outchan sending: basic headers
52 (including Content-Length computed using 'body' argument), headers probided
53 via 'headers' argument, body given via 'body' argument. Default response
54 status is 200, default response HTTP version is Http_common.http_version *)
56 ?body:string -> ?headers:(string * string) list ->
57 ?version:Http_types.version -> ?code:int -> ?status:Http_types.status ->
61 (** send a 404 (not found) HTTP response *)
62 val respond_not_found:
63 url:string -> ?version: Http_types.version -> out_channel -> unit
65 (** send a 403 (forbidden) HTTP response *)
66 val respond_forbidden:
67 url:string -> ?version: Http_types.version -> out_channel -> unit
69 (** send a "redirection" class response, optional body argument contains data
70 that will be displayed in the body of the response, default response status is
71 302 (moved permanently), only redirection status are accepted by this
72 function, other values will raise Failure *)
74 location:string -> ?body:string ->
75 ?version: Http_types.version ->
76 ?code: int -> ?status: Http_types.redirection_status ->
80 (** send an "error" response (i.e. 400 <= status < 600), optional body
81 argument as per send_redirect, default response status is 400 (bad request),
82 only error status are accepted by this function, other values will
86 ?version: Http_types.version ->
87 ?code: int -> ?status: Http_types.error_status ->
91 (** tipical static pages http daemon behaviour, if requested url is a file,
92 return it, it it is a directory return a directory listing of it *)
94 fname:string -> ?version: Http_types.version -> out_channel -> unit
96 (** respond using a prebuilt Http_types.response object *)
97 val respond_with: Http_types.response -> out_channel -> unit
99 (** create an HTTP daemon listening on 'addr':'port' (defaults are
100 addr:"0.0.0.0" and port:80), callback is the user supplied function which
101 receive as a first parameter the path required by the the HTTP client as a
102 string, and a list of pair <parameter, value> representing parameters passed
103 via GET. The last argument of the callback is an output_channel connected to
104 the HTTP client to which the user can write directly. 'timeout' parameter sets
105 a timeout for each request processed by the daemon, if it's set to None,
106 daemon waits forever for completed requests (use with care!), default is 5
107 minute. 'mode' parameter has 3 possible values: `Single means that all request
108 are handled by the same process, `Fork means that each request is handled by a
109 separate process, `Thread means that each request is handled by a separate
110 thread, default is `Fork; 'root' (mnemonic "document root") is the directory
111 where the daemon chdir before starting up, default is current working
114 ?addr: string -> ?port: int ->
115 ?timeout: int option -> ?mode: Http_types.daemon_mode -> ?root: string ->
116 (string -> (string * string) list -> out_channel -> unit) ->
119 (** identical to 'start' above but callback receive two arguments, the second
120 one is an out_channel as per 'start', but the secondo one is a Request.request
123 ?addr: string -> ?port: int ->
124 ?timeout: int option -> ?mode: Http_types.daemon_mode -> ?root: string ->
125 (Http_types.request -> out_channel -> unit) ->
128 (** Trivial static pages HTTP daemon *)
131 val callback : string -> 'a -> out_channel -> unit
132 val start : ?addr:string -> ?port:int -> unit -> unit
135 class daemon: ?addr: string -> ?port: int -> unit -> Http_types.daemon