]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/ocaml-http/http_types.ml
- added methods to retrieve client IP address related info
[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 = [ `GET ]
28
29 type daemon_mode = [ `Single | `Fork | `Thread ]
30
31 type tcp_server =
32   sockaddr:Unix.sockaddr -> timeout:int option ->
33   (in_channel -> out_channel -> unit) ->
34     unit
35
36 type informational_substatus =
37   [ `Continue
38   | `Switching_protocols
39   ]
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
51 type redirection_substatus =
52   [ `Multiple_choices
53   | `Moved_permanently
54   | `Found
55   | `See_other
56   | `Not_modified
57   | `Use_proxy
58   | `Temporary_redirect
59   ]
60
61 type client_error_substatus =
62   [ `Bad_request
63   | `Unauthorized
64   | `Payment_required
65   | `Forbidden
66   | `Not_found
67   | `Method_not_allowed
68   | `Not_acceptable
69   | `Proxy_authentication_required
70   | `Request_time_out
71   | `Conflict
72   | `Gone
73   | `Length_required
74   | `Precondition_failed
75   | `Request_entity_too_large
76   | `Request_URI_too_large
77   | `Unsupported_media_type
78   | `Requested_range_not_satisfiable
79   | `Expectation_failed
80   ]
81
82 type server_error_substatus =
83   [ `Internal_server_error
84   | `Not_implemented
85   | `Bad_gateway
86   | `Service_unavailable
87   | `Gateway_time_out
88   | `HTTP_version_not_supported
89   ]
90
91 type informational_status = [ `Informational of informational_substatus ]
92 type success_status = [ `Success of success_substatus ]
93 type redirection_status = [ `Redirection of redirection_substatus ]
94 type client_error_status = [ `Client_error of client_error_substatus ]
95 type server_error_status = [ `Server_error of server_error_substatus ]
96
97 type error_status =
98   [ client_error_status
99   | server_error_status
100   ]
101
102 type status =
103   [ informational_status
104   | success_status
105   | redirection_status
106   | client_error_status
107   | server_error_status
108   ]
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_code of int
115 exception Invalid_status of status
116
117 exception Malformed_query of string
118 exception Malformed_query_part of string * string
119 exception Unsupported_method of string
120 exception Unsupported_HTTP_version of string
121 exception Malformed_request_URI of string
122 exception Malformed_request of string
123
124 exception Param_not_found of string
125
126 exception Invalid_status_line of string
127 exception Header_not_found of string
128
129 class type response =
130   object
131     method version: version
132     method setVersion: version -> unit
133     method code: int
134     method setCode: int -> unit
135     method status: status
136     method setStatus: status -> unit
137     method reason: string
138     method setReason: string -> unit
139     method statusLine: string
140     method setStatusLine: string -> unit
141     method isInformational: bool
142     method isSuccess: bool
143     method isRedirection: bool
144     method isClientError: bool
145     method isServerError: bool
146     method isError: bool
147     method contents: string
148     method setContents: string -> unit
149     method contentsBuf: Buffer.t
150     method setContentsBuf: Buffer.t -> unit
151     method addContents: string -> unit
152     method addContentsBuf: Buffer.t -> unit
153     method addHeader: name:string -> value:string -> unit
154     method addHeaders: (string * string) list -> unit
155     method addBasicHeaders: unit
156     method replaceHeader: name:string -> value:string -> unit
157     method replaceHeaders: (string * string) list -> unit
158     method removeHeader: name:string -> unit
159     method hasHeader: name:string -> bool
160     method header: name:string -> string
161     method headers: (string * string) list
162     method contentType: string
163     method setContentType: string -> unit
164     method contentEncoding: string
165     method setContentEncoding: string -> unit
166     method date: string
167     method setDate: string -> unit
168     method expires: string
169     method setExpires: string -> unit
170     method server: string
171     method setServer: string -> unit
172     method toString: string
173     method serialize: out_channel -> unit
174   end
175 class type request =
176   object
177     method uri: string
178     method path: string
179     method param: string -> string
180     method paramAll: string -> string list
181     method params: (string * string) list
182     method clientSockaddr: Unix.sockaddr
183     method clientAddr: string
184     method clientPort: int
185   end
186 class type connection =
187   object
188     method getRequest: request option
189     method respond_with: response -> unit
190     method close: unit
191   end
192 class type daemon =
193   object
194     method accept: connection
195     method getRequest: request * connection
196   end
197