2 OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
4 Copyright (C) <2002-2007> Stefano Zacchiroli <zack@cs.unibo.it>
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.
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.
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
21 (** Type definitions *)
23 type version = [ `HTTP_1_0 | `HTTP_1_1 ]
24 type meth = [ `GET | `POST ]
25 type daemon_mode = [ `Single | `Fork | `Thread ]
28 sockaddr:Unix.sockaddr -> timeout:int option ->
29 (in_channel -> out_channel -> unit) ->
33 [ `Basic of string * string (* username, password *)
36 type informational_substatus =
38 | `Switching_protocols
40 type success_substatus =
44 | `Non_authoritative_information
49 type redirection_substatus =
58 type client_error_substatus =
66 | `Proxy_authentication_required
71 | `Precondition_failed
72 | `Request_entity_too_large
73 | `Request_URI_too_large
74 | `Unsupported_media_type
75 | `Requested_range_not_satisfiable
78 type server_error_substatus =
79 [ `Internal_server_error
82 | `Service_unavailable
84 | `HTTP_version_not_supported
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 ]
96 [ informational_status
100 | server_error_status
103 type status_code = [ `Code of int | `Status of status ]
107 | InChanSrc of in_channel
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
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 -> ?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
169 class type response = object
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
185 method addBasicHeaders: unit
186 method contentType: string
187 method setContentType: string -> unit
188 method contentEncoding: string
189 method setContentEncoding: string -> unit
191 method setDate: string -> unit
192 method expires: string
193 method setExpires: string -> unit
194 method server: string
195 method setServer: string -> unit
198 class type connection =
200 method getRequest: request option
201 method respond_with: response -> unit
206 method accept: connection
207 method getRequest: request * connection
212 auth: (string * auth_info) option;
213 callback: request -> out_channel -> unit;
216 root_dir: string option;
217 exn_handler: (exn -> out_channel -> unit) option;