]> matita.cs.unibo.it Git - helm.git/blob - DEVEL/ocaml-http/0.1.4-3/http_types.ml
tagging
[helm.git] / DEVEL / ocaml-http / 0.1.4-3 / http_types.ml
1 (*
2   OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
3
4   Copyright (C) <2002-2007> Stefano Zacchiroli <zack@cs.unibo.it>
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU Library General Public License as
8   published by the Free Software Foundation, version 2.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU Library General Public License for more details.
14
15   You should have received a copy of the GNU Library General Public
16   License along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18   USA
19 *)
20
21 (** Type definitions *)
22
23 type version = [ `HTTP_1_0 | `HTTP_1_1 ]
24 type meth = [ `GET | `POST ]
25 type daemon_mode = [ `Single | `Fork | `Thread ]
26
27 type tcp_server =
28   sockaddr:Unix.sockaddr -> timeout:int option ->
29   (in_channel -> out_channel -> unit) ->
30     unit
31
32 type auth_info =
33   [ `Basic of string * string (* username, password *)
34   ]
35
36 type informational_substatus =
37   [ `Continue
38   | `Switching_protocols
39   ]
40 type success_substatus =
41   [ `OK
42   | `Created
43   | `Accepted
44   | `Non_authoritative_information
45   | `No_content
46   | `Reset_content
47   | `Partial_content
48   ]
49 type redirection_substatus =
50   [ `Multiple_choices
51   | `Moved_permanently
52   | `Found
53   | `See_other
54   | `Not_modified
55   | `Use_proxy
56   | `Temporary_redirect
57   ]
58 type client_error_substatus =
59   [ `Bad_request
60   | `Unauthorized
61   | `Payment_required
62   | `Forbidden
63   | `Not_found
64   | `Method_not_allowed
65   | `Not_acceptable
66   | `Proxy_authentication_required
67   | `Request_time_out
68   | `Conflict
69   | `Gone
70   | `Length_required
71   | `Precondition_failed
72   | `Request_entity_too_large
73   | `Request_URI_too_large
74   | `Unsupported_media_type
75   | `Requested_range_not_satisfiable
76   | `Expectation_failed
77   ]
78 type server_error_substatus =
79   [ `Internal_server_error
80   | `Not_implemented
81   | `Bad_gateway
82   | `Service_unavailable
83   | `Gateway_time_out
84   | `HTTP_version_not_supported
85   ]
86 type informational_status = [ `Informational of informational_substatus ]
87 type success_status = [ `Success of success_substatus ]
88 type redirection_status = [ `Redirection of redirection_substatus ]
89 type client_error_status = [ `Client_error of client_error_substatus ]
90 type server_error_status = [ `Server_error of server_error_substatus ]
91 type error_status =
92   [ client_error_status
93   | server_error_status
94   ]
95 type status =
96   [ informational_status
97   | success_status
98   | redirection_status
99   | client_error_status
100   | server_error_status
101   ]
102
103 type status_code = [ `Code of int | `Status of status ]
104
105 type file_source =
106   | FileSrc of string
107   | InChanSrc of in_channel
108
109 exception Invalid_header of string
110 exception Invalid_header_name of string
111 exception Invalid_header_value of string
112 exception Invalid_HTTP_version of string
113 exception Invalid_HTTP_method of string
114 exception Invalid_code of int
115 exception Malformed_URL of string
116 exception Malformed_query of string
117 exception Malformed_query_part of string * string
118 exception Malformed_request_URI of string
119 exception Malformed_cookies 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 cookies: (string * string) list option
166     method authorization: auth_info option
167   end
168
169 class type response = object
170     inherit message
171     method code: int
172     method setCode: int -> unit
173     method status: status
174     method setStatus: status -> unit
175     method reason: string
176     method setReason: string -> unit
177     method statusLine: string
178     method setStatusLine: string -> unit
179     method isInformational: bool
180     method isSuccess: bool
181     method isRedirection: bool
182     method isClientError: bool
183     method isServerError: bool
184     method isError: bool
185     method addBasicHeaders: unit
186     method contentType: string
187     method setContentType: string -> unit
188     method contentEncoding: string
189     method setContentEncoding: string -> unit
190     method date: string
191     method setDate: string -> unit
192     method expires: string
193     method setExpires: string -> unit
194     method server: string
195     method setServer: string -> unit
196   end
197
198 class type connection =
199   object
200     method getRequest: request option
201     method respond_with: response -> unit
202     method close: unit
203   end
204 class type daemon =
205   object
206     method accept: connection
207     method getRequest: request * connection
208   end
209
210 type daemon_spec = {
211   address: string;
212   auth: (string * auth_info) option;
213   callback: request -> out_channel -> unit;
214   mode: daemon_mode;
215   port: int;
216   root_dir: string option;
217   exn_handler: (exn -> out_channel -> unit) option;
218   timeout: int option;
219   auto_close: bool;
220 }
221