]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/ocaml-http/http_types.ml
ocaml 3.09 transition
[helm.git] / helm / DEVEL / ocaml-http / http_types.ml
index 909b4681adc2a74eb0214ac2a7cecfab3febde96..5c88b212ed010990015a936355824685f6d737d8 100644 (file)
@@ -2,43 +2,27 @@
 (*
   OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
 
-  Copyright (C) <2002> Stefano Zacchiroli <zack@cs.unibo.it>
+  Copyright (C) <2002-2005> Stefano Zacchiroli <zack@cs.unibo.it>
 
   This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+  it under the terms of the GNU Library General Public License as
+  published by the Free Software Foundation, version 2.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+  GNU Library General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  You should have received a copy of the GNU Library General Public
+  License along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+  USA
 *)
 
-  (** HTTP version, actually only 1.0 and 1.1 are supported. Note that
-  'supported' here means only 'accepted inside a HTTP request line', no
-  different behaviours are actually implemented depending on HTTP version *)
-type version =
-  [ `HTTP_1_0
-  | `HTTP_1_1
-  ]
-
-  (** HTTP method, actually only GET and POST methods are supported *)
-type meth =
-  [ `GET
-  | `POST
-  ]
+(** Type definitions *)
 
-  (** Daemon behaviour wrt request handling. `Single mode use a single process
-  to handle all requests, no request is served until a previous one has been
-  fully served. `Fork mode fork a new process for each request, the new process
-  will execute the callback function and then exit. `Thread mode create a new
-  thread for each request, the new thread will execute the callback function and
-  then exit, threads can communicate using standard OCaml Thread library. *)
+type version = [ `HTTP_1_0 | `HTTP_1_1 ]
+type meth = [ `GET | `POST ]
 type daemon_mode = [ `Single | `Fork | `Thread ]
 
 type tcp_server =
@@ -46,11 +30,14 @@ type tcp_server =
   (in_channel -> out_channel -> unit) ->
     unit
 
+type auth_info =
+  [ `Basic of string * string (* username, password *)
+  ]
+
 type informational_substatus =
   [ `Continue
   | `Switching_protocols
   ]
-
 type success_substatus =
   [ `OK
   | `Created
@@ -60,7 +47,6 @@ type success_substatus =
   | `Reset_content
   | `Partial_content
   ]
-
 type redirection_substatus =
   [ `Multiple_choices
   | `Moved_permanently
@@ -70,7 +56,6 @@ type redirection_substatus =
   | `Use_proxy
   | `Temporary_redirect
   ]
-
 type client_error_substatus =
   [ `Bad_request
   | `Unauthorized
@@ -91,7 +76,6 @@ type client_error_substatus =
   | `Requested_range_not_satisfiable
   | `Expectation_failed
   ]
-
 type server_error_substatus =
   [ `Internal_server_error
   | `Not_implemented
@@ -100,18 +84,15 @@ type server_error_substatus =
   | `Gateway_time_out
   | `HTTP_version_not_supported
   ]
-
 type informational_status = [ `Informational of informational_substatus ]
 type success_status = [ `Success of success_substatus ]
 type redirection_status = [ `Redirection of redirection_substatus ]
 type client_error_status = [ `Client_error of client_error_substatus ]
 type server_error_status = [ `Server_error of server_error_substatus ]
-
 type error_status =
   [ client_error_status
   | server_error_status
   ]
-
 type status =
   [ informational_status
   | success_status
@@ -120,46 +101,39 @@ type status =
   | server_error_status
   ]
 
+type status_code = [ `Code of int | `Status of status ]
+
+type file_source =
+  | FileSrc of string
+  | InChanSrc of in_channel
+
 exception Invalid_header of string
 exception Invalid_header_name of string
 exception Invalid_header_value of string
 exception Invalid_HTTP_version of string
 exception Invalid_HTTP_method of string
 exception Invalid_code of int
-exception Invalid_status of status
-
+exception Malformed_URL of string
 exception Malformed_query of string
 exception Malformed_query_part of string * string
-exception Unsupported_method of string
-exception Unsupported_HTTP_version of string
 exception Malformed_request_URI of string
 exception Malformed_request of string
-
+exception Malformed_response of string
 exception Param_not_found of string
-
 exception Invalid_status_line of string
 exception Header_not_found of string
-
-  (** raisable by callback functions to make main daemon quit, this is the only
-  'clean' way to make start functions return *)
 exception Quit
+exception Unauthorized of string
 
 class type message = object
-
-    method version: version
+    method version: version option
     method setVersion: version -> unit
-
     method body: string
     method setBody: string -> unit
     method bodyBuf: Buffer.t
     method setBodyBuf: Buffer.t -> unit
     method addBody: string -> unit
     method addBodyBuf: Buffer.t -> unit
-
-    (** header name comparison are performed in a case-insensitive manner as
-    required by RFC2616, actually the implementation works converting all header
-    names in lowercase *)
-
     method addHeader: name:string -> value:string -> unit
     method addHeaders: (string * string) list -> unit
     method replaceHeader: name:string -> value:string -> unit
@@ -168,39 +142,31 @@ class type message = object
     method hasHeader: name:string -> bool
     method header: name:string -> string
     method headers: (string * string) list
-
     method clientSockaddr: Unix.sockaddr
     method clientAddr: string
     method clientPort: int
-
     method serverSockaddr: Unix.sockaddr
     method serverAddr: string
     method serverPort: int
-
     method toString: string
     method serialize: out_channel -> unit
-
   end
 
 class type request = object
-
     inherit message
-
     method meth: meth
     method uri: string
     method path: string
-    method param: ?meth:meth -> string -> string
+    method param: ?meth:meth -> ?default:string -> string -> string
     method paramAll: ?meth:meth -> string -> string list
     method params: (string * string) list
     method params_GET: (string * string) list
     method params_POST: (string * string) list
-
+    method authorization: auth_info option
   end
 
 class type response = object
-
     inherit message
-
     method code: int
     method setCode: int -> unit
     method status: status
@@ -209,14 +175,12 @@ class type response = object
     method setReason: string -> unit
     method statusLine: string
     method setStatusLine: string -> unit
-
     method isInformational: bool
     method isSuccess: bool
     method isRedirection: bool
     method isClientError: bool
     method isServerError: bool
     method isError: bool
-
     method addBasicHeaders: unit
     method contentType: string
     method setContentType: string -> unit
@@ -228,7 +192,6 @@ class type response = object
     method setExpires: string -> unit
     method server: string
     method setServer: string -> unit
-
   end
 
 class type connection =
@@ -237,10 +200,20 @@ class type connection =
     method respond_with: response -> unit
     method close: unit
   end
-
 class type daemon =
   object
     method accept: connection
     method getRequest: request * connection
   end
 
+type daemon_spec = {
+  address: string;
+  auth: (string * auth_info) option;
+  callback: request -> out_channel -> unit;
+  mode: daemon_mode;
+  port: int;
+  root_dir: string option;
+  exn_handler: (exn -> out_channel -> unit) option;
+  timeout: int option;
+}
+