3 OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
5 Copyright (C) <2002-2004> Stefano Zacchiroli <zack@cs.unibo.it>
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.
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.
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
22 (** Type definitions *)
24 type version = [ `HTTP_1_0 | `HTTP_1_1 ]
25 type meth = [ `GET | `POST ]
26 type daemon_mode = [ `Single | `Fork | `Thread ]
29 sockaddr:Unix.sockaddr -> timeout:int option ->
30 (in_channel -> out_channel -> unit) ->
34 [ `Basic of string * string (* username, password *)
37 type informational_substatus =
39 | `Switching_protocols
41 type success_substatus =
45 | `Non_authoritative_information
50 type redirection_substatus =
59 type client_error_substatus =
67 | `Proxy_authentication_required
72 | `Precondition_failed
73 | `Request_entity_too_large
74 | `Request_URI_too_large
75 | `Unsupported_media_type
76 | `Requested_range_not_satisfiable
79 type server_error_substatus =
80 [ `Internal_server_error
83 | `Service_unavailable
85 | `HTTP_version_not_supported
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 ]
97 [ informational_status
100 | client_error_status
101 | server_error_status
104 type status_code = [ `Code of int | `Status of status ]
108 | InChanSrc of in_channel
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
126 exception Unauthorized of string
128 class type message = object
129 method version: version option
130 method setVersion: version -> unit
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
155 class type request = object
160 method param: ?meth:meth -> 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
168 class type response = object
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
184 method addBasicHeaders: unit
185 method contentType: string
186 method setContentType: string -> unit
187 method contentEncoding: string
188 method setContentEncoding: string -> unit
190 method setDate: string -> unit
191 method expires: string
192 method setExpires: string -> unit
193 method server: string
194 method setServer: string -> unit
197 class type connection =
199 method getRequest: request option
200 method respond_with: response -> unit
205 method accept: connection
206 method getRequest: request * connection
211 auth: (string * auth_info) option;
212 callback: request -> out_channel -> unit;
215 root_dir: string option;
216 exn_handler: (exn -> out_channel -> unit) option;