]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/ocaml-http/http_daemon.mli
no longer use -pack and Http.*, now interface is the usual Http_*
[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
95   sets 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 *)
98 val start:
99   ?addr: string -> ?port: int -> ?timeout: int option ->
100   (string -> (string * string) list -> out_channel -> unit) ->
101     unit
102
103   (** identical to 'start' above but callback receive two arguments, the second
104   one is an out_channel as per 'start', but the secondo one is a Request.request
105   object *)
106 val start':
107   ?addr: string -> ?port: int -> ?timeout: int option ->
108   (Http_types.request -> out_channel -> unit) ->
109     unit
110
111   (** Trivial static pages HTTP daemon *)
112 module Trivial :
113   sig
114     val callback : string -> 'a -> out_channel -> unit
115     val start : ?addr:string -> ?port:int -> unit -> unit
116   end
117