]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/ocaml-http/http_daemon.mli
- split http_parser module (all code that parse http requests and
[helm.git] / helm / DEVEL / ocaml-http / http_daemon.mli
1
2 (*
3   OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
4
5   Copyright (C) <2002> Stefano Zacchiroli <zack@cs.unibo.it>
6
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.
11
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.
16
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
20 *)
21
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
25
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 *)
29 val send_status_line:
30   ?version: Http_types.version -> ?code: int -> ?status: Http_types.status ->
31   out_channel ->
32     unit
33
34   (** like send_status_line but additionally will also send "Date" and "Server"
35   standard headers *)
36 val send_basic_headers:
37   ?version: Http_types.version -> ?code: int -> ?status: Http_types.status ->
38   out_channel ->
39     unit
40
41   (** send an HTTP header on outchan *)
42 val send_header: header: string -> value: string -> out_channel -> unit
43
44   (** as send_header, but for a list of pairs <header, value> *)
45 val send_headers: headers:(string * string) list -> out_channel -> unit
46
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
50
51   (** send a 404 (not found) HTTP response *)
52 val respond_not_found:
53   url:string -> ?version: Http_types.version -> out_channel -> unit
54
55   (** send a 403 (forbidden) HTTP response *)
56 val respond_forbidden:
57   url:string -> ?version: Http_types.version -> out_channel -> unit
58
59   (** send a "redirection" class response, optional body argument contains data
60   that will be displayed in the body of the response, default response status is
61   302 (moved permanently), only redirection status are accepted by this
62   function, other values will @raise Failure *)
63 val respond_redirect:
64   location:string -> ?body:string ->
65   ?version: Http_types.version ->
66   ?code: int -> ?status: Http_types.redirection_status ->
67   out_channel ->
68     unit
69
70   (** send an "error" response (i.e. 400 <= status < 600), optional body
71   argument as per send_redirect, default response status is 400 (bad request),
72   only error status are accepted by this function, other values will
73   @raise Failure *)
74 val respond_error:
75   ?body:string ->
76   ?version: Http_types.version ->
77   ?code: int -> ?status: Http_types.error_status ->
78   out_channel ->
79     unit
80
81   (** tipical static pages http daemon behaviour, if requested url is a file,
82   return it, it it is a directory return a directory listing of it *)
83 val respond_file:
84   fname:string -> ?version: Http_types.version -> out_channel -> unit
85
86   (** respond using a prebuilt Http_types.response object *)
87 val respond_with: Http_types.response -> out_channel -> unit
88
89   (** create an HTTP daemon listening on 'addr':'port' (defaults are
90   addr:"0.0.0.0" and port:80), callback is the user supplied function which
91   receive as a first parameter the path required by the the HTTP client as a
92   string, and a list of pair <parameter, value> representing parameters passed
93   via GET. The last argument of the callback is an output_channel connected to
94   the HTTP client to which the user can write directly. 'timeout' parameter sets
95   a timeout for each request processed by the daemon, if it's set to None,
96   daemon waits forever for completed requests (use with care!), default is 5
97   minute. 'fork' parameter (default 'true') sets whether the daemon forks a
98   child for each request or not, if children aren't forked request are server
99   one at a time (backlog is 10) and callbacks live in the same address space of
100   the process invoking 'start' *)
101 val start:
102   ?addr: string -> ?port: int -> ?timeout: int option -> ?fork: bool ->
103   (string -> (string * string) list -> out_channel -> unit) ->
104     unit
105
106   (** identical to 'start' above but callback receive two arguments, the second
107   one is an out_channel as per 'start', but the secondo one is a Request.request
108   object *)
109 val start':
110   ?addr: string -> ?port: int -> ?timeout: int option -> ?fork: bool ->
111   (Http_types.request -> out_channel -> unit) ->
112     unit
113
114   (** Trivial static pages HTTP daemon *)
115 module Trivial :
116   sig
117     val callback : string -> 'a -> out_channel -> unit
118     val start : ?addr:string -> ?port:int -> unit -> unit
119   end
120