]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/ocaml-http/http_types.ml
ocaml 3.09 transition
[helm.git] / helm / DEVEL / ocaml-http / http_types.ml
1
2 (*
3   OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
4
5   Copyright (C) <2002-2005> 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 Library General Public License as
9   published by the Free Software Foundation, version 2.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU Library General Public License for more details.
15
16   You should have received a copy of the GNU Library General Public
17   License along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   USA
20 *)
21
22 (** Type definitions *)
23
24 type version = [ `HTTP_1_0 | `HTTP_1_1 ]
25 type meth = [ `GET | `POST ]
26 type daemon_mode = [ `Single | `Fork | `Thread ]
27
28 type tcp_server =
29   sockaddr:Unix.sockaddr -> timeout:int option ->
30   (in_channel -> out_channel -> unit) ->
31     unit
32
33 type auth_info =
34   [ `Basic of string * string (* username, password *)
35   ]
36
37 type informational_substatus =
38   [ `Continue
39   | `Switching_protocols
40   ]
41 type success_substatus =
42   [ `OK
43   | `Created
44   | `Accepted
45   | `Non_authoritative_information
46   | `No_content
47   | `Reset_content
48   | `Partial_content
49   ]
50 type redirection_substatus =
51   [ `Multiple_choices
52   | `Moved_permanently
53   | `Found
54   | `See_other
55   | `Not_modified
56   | `Use_proxy
57   | `Temporary_redirect
58   ]
59 type client_error_substatus =
60   [ `Bad_request
61   | `Unauthorized
62   | `Payment_required
63   | `Forbidden
64   | `Not_found
65   | `Method_not_allowed
66   | `Not_acceptable
67   | `Proxy_authentication_required
68   | `Request_time_out
69   | `Conflict
70   | `Gone
71   | `Length_required
72   | `Precondition_failed
73   | `Request_entity_too_large
74   | `Request_URI_too_large
75   | `Unsupported_media_type
76   | `Requested_range_not_satisfiable
77   | `Expectation_failed
78   ]
79 type server_error_substatus =
80   [ `Internal_server_error
81   | `Not_implemented
82   | `Bad_gateway
83   | `Service_unavailable
84   | `Gateway_time_out
85   | `HTTP_version_not_supported
86   ]
87 type informational_status = [ `Informational of informational_substatus ]
88 type success_status = [ `Success of success_substatus ]
89 type redirection_status = [ `Redirection of redirection_substatus ]
90 type client_error_status = [ `Client_error of client_error_substatus ]
91 type server_error_status = [ `Server_error of server_error_substatus ]
92 type error_status =
93   [ client_error_status
94   | server_error_status
95   ]
96 type status =
97   [ informational_status
98   | success_status
99   | redirection_status
100   | client_error_status
101   | server_error_status
102   ]
103
104 type status_code = [ `Code of int | `Status of status ]
105
106 type file_source =
107   | FileSrc of string
108   | InChanSrc of in_channel
109
110 exception Invalid_header of string
111 exception Invalid_header_name of string
112 exception Invalid_header_value of string
113 exception Invalid_HTTP_version of string
114 exception Invalid_HTTP_method of string
115 exception Invalid_code of int
116 exception Malformed_URL of string
117 exception Malformed_query of string
118 exception Malformed_query_part of string * string
119 exception Malformed_request_URI of string
120 exception Malformed_request of string
121 exception Malformed_response of string
122 exception Param_not_found of string
123 exception Invalid_status_line of string
124 exception Header_not_found of string
125 exception Quit
126 exception Unauthorized of string
127
128 class type message = object
129     method version: version option
130     method setVersion: version -> unit
131     method body: string
132     method setBody: string -> unit
133     method bodyBuf: Buffer.t
134     method setBodyBuf: Buffer.t -> unit
135     method addBody: string -> unit
136     method addBodyBuf: Buffer.t -> unit
137     method addHeader: name:string -> value:string -> unit
138     method addHeaders: (string * string) list -> unit
139     method replaceHeader: name:string -> value:string -> unit
140     method replaceHeaders: (string * string) list -> unit
141     method removeHeader: name:string -> unit
142     method hasHeader: name:string -> bool
143     method header: name:string -> string
144     method headers: (string * string) list
145     method clientSockaddr: Unix.sockaddr
146     method clientAddr: string
147     method clientPort: int
148     method serverSockaddr: Unix.sockaddr
149     method serverAddr: string
150     method serverPort: int
151     method toString: string
152     method serialize: out_channel -> unit
153   end
154
155 class type request = object
156     inherit message
157     method meth: meth
158     method uri: string
159     method path: string
160     method param: ?meth:meth -> ?default:string -> string -> string
161     method paramAll: ?meth:meth -> string -> string list
162     method params: (string * string) list
163     method params_GET: (string * string) list
164     method params_POST: (string * string) list
165     method authorization: auth_info option
166   end
167
168 class type response = object
169     inherit message
170     method code: int
171     method setCode: int -> unit
172     method status: status
173     method setStatus: status -> unit
174     method reason: string
175     method setReason: string -> unit
176     method statusLine: string
177     method setStatusLine: string -> unit
178     method isInformational: bool
179     method isSuccess: bool
180     method isRedirection: bool
181     method isClientError: bool
182     method isServerError: bool
183     method isError: bool
184     method addBasicHeaders: unit
185     method contentType: string
186     method setContentType: string -> unit
187     method contentEncoding: string
188     method setContentEncoding: string -> unit
189     method date: string
190     method setDate: string -> unit
191     method expires: string
192     method setExpires: string -> unit
193     method server: string
194     method setServer: string -> unit
195   end
196
197 class type connection =
198   object
199     method getRequest: request option
200     method respond_with: response -> unit
201     method close: unit
202   end
203 class type daemon =
204   object
205     method accept: connection
206     method getRequest: request * connection
207   end
208
209 type daemon_spec = {
210   address: string;
211   auth: (string * auth_info) option;
212   callback: request -> out_channel -> unit;
213   mode: daemon_mode;
214   port: int;
215   root_dir: string option;
216   exn_handler: (exn -> out_channel -> unit) option;
217   timeout: int option;
218 }
219