]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/ocaml-http/http_types.ml
276d2e3aa47048651660c5093546667a30bcddd2
[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> 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 type version =
23   [ `HTTP_1_0
24   | `HTTP_1_1
25   ]
26
27 type meth =
28   [ `GET
29   | `POST
30   ]
31
32 type daemon_mode = [ `Single | `Fork | `Thread ]
33
34 type tcp_server =
35   sockaddr:Unix.sockaddr -> timeout:int option ->
36   (in_channel -> out_channel -> unit) ->
37     unit
38
39 type informational_substatus =
40   [ `Continue
41   | `Switching_protocols
42   ]
43
44 type success_substatus =
45   [ `OK
46   | `Created
47   | `Accepted
48   | `Non_authoritative_information
49   | `No_content
50   | `Reset_content
51   | `Partial_content
52   ]
53
54 type redirection_substatus =
55   [ `Multiple_choices
56   | `Moved_permanently
57   | `Found
58   | `See_other
59   | `Not_modified
60   | `Use_proxy
61   | `Temporary_redirect
62   ]
63
64 type client_error_substatus =
65   [ `Bad_request
66   | `Unauthorized
67   | `Payment_required
68   | `Forbidden
69   | `Not_found
70   | `Method_not_allowed
71   | `Not_acceptable
72   | `Proxy_authentication_required
73   | `Request_time_out
74   | `Conflict
75   | `Gone
76   | `Length_required
77   | `Precondition_failed
78   | `Request_entity_too_large
79   | `Request_URI_too_large
80   | `Unsupported_media_type
81   | `Requested_range_not_satisfiable
82   | `Expectation_failed
83   ]
84
85 type server_error_substatus =
86   [ `Internal_server_error
87   | `Not_implemented
88   | `Bad_gateway
89   | `Service_unavailable
90   | `Gateway_time_out
91   | `HTTP_version_not_supported
92   ]
93
94 type informational_status = [ `Informational of informational_substatus ]
95 type success_status = [ `Success of success_substatus ]
96 type redirection_status = [ `Redirection of redirection_substatus ]
97 type client_error_status = [ `Client_error of client_error_substatus ]
98 type server_error_status = [ `Server_error of server_error_substatus ]
99
100 type error_status =
101   [ client_error_status
102   | server_error_status
103   ]
104
105 type status =
106   [ informational_status
107   | success_status
108   | redirection_status
109   | client_error_status
110   | server_error_status
111   ]
112
113 exception Invalid_header of string
114 exception Invalid_header_name of string
115 exception Invalid_header_value of string
116 exception Invalid_HTTP_version of string
117 exception Invalid_HTTP_method of string
118 exception Invalid_code of int
119 exception Invalid_status of status
120
121 exception Malformed_query of string
122 exception Malformed_query_part of string * string
123 exception Unsupported_method of string
124 exception Unsupported_HTTP_version of string
125 exception Malformed_request_URI of string
126 exception Malformed_request of string
127
128 exception Param_not_found of string
129
130 exception Invalid_status_line of string
131 exception Header_not_found of string
132
133 class type message = object
134
135     method version: version
136     method setVersion: version -> unit
137
138     method body: string
139     method setBody: string -> unit
140     method bodyBuf: Buffer.t
141     method setBodyBuf: Buffer.t -> unit
142     method addBody: string -> unit
143     method addBodyBuf: Buffer.t -> unit
144
145     method addHeader: name:string -> value:string -> unit
146     method addHeaders: (string * string) list -> unit
147     method replaceHeader: name:string -> value:string -> unit
148     method replaceHeaders: (string * string) list -> unit
149     method removeHeader: name:string -> unit
150     method hasHeader: name:string -> bool
151     method header: name:string -> string
152     method headers: (string * string) list
153
154     method clientSockaddr: Unix.sockaddr
155     method clientAddr: string
156     method clientPort: int
157
158     method serverSockaddr: Unix.sockaddr
159     method serverAddr: string
160     method serverPort: int
161
162     method toString: string
163     method serialize: out_channel -> unit
164
165   end
166
167 class type request = object
168
169     inherit message
170
171     method meth: meth
172     method uri: string
173     method path: string
174     method param: ?meth:meth -> string -> string
175     method paramAll: ?meth:meth -> string -> string list
176     method params: (string * string) list
177     method params_GET: (string * string) list
178     method params_POST: (string * string) list
179
180   end
181
182 class type response = object
183
184     inherit message
185
186     method code: int
187     method setCode: int -> unit
188     method status: status
189     method setStatus: status -> unit
190     method reason: string
191     method setReason: string -> unit
192     method statusLine: string
193     method setStatusLine: string -> unit
194
195     method isInformational: bool
196     method isSuccess: bool
197     method isRedirection: bool
198     method isClientError: bool
199     method isServerError: bool
200     method isError: bool
201
202     method addBasicHeaders: unit
203     method contentType: string
204     method setContentType: string -> unit
205     method contentEncoding: string
206     method setContentEncoding: string -> unit
207     method date: string
208     method setDate: string -> unit
209     method expires: string
210     method setExpires: string -> unit
211     method server: string
212     method setServer: string -> unit
213
214   end
215
216 class type connection =
217   object
218     method getRequest: request option
219     method respond_with: response -> unit
220     method close: unit
221   end
222
223 class type daemon =
224   object
225     method accept: connection
226     method getRequest: request * connection
227   end
228