X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Focaml-http%2Fhttp_types.ml;h=909b4681adc2a74eb0214ac2a7cecfab3febde96;hb=89262281b6e83bd2321150f81f1a0583645eb0c8;hp=f567c227bbb51e066f85542d86b9fd2a600f4597;hpb=cb071f7475e2fe225de02a9855466c3487fd035f;p=helm.git diff --git a/helm/DEVEL/ocaml-http/http_types.ml b/helm/DEVEL/ocaml-http/http_types.ml index f567c227b..909b4681a 100644 --- a/helm/DEVEL/ocaml-http/http_types.ml +++ b/helm/DEVEL/ocaml-http/http_types.ml @@ -19,13 +19,26 @@ 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 ] -type meth = [ `GET ] + (** HTTP method, actually only GET and POST methods are supported *) +type meth = + [ `GET + | `POST + ] + (** 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 daemon_mode = [ `Single | `Fork | `Thread ] type tcp_server = @@ -107,10 +120,87 @@ type status = | server_error_status ] -class type response = - object +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_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 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 + +class type message = object + method version: version 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 + method replaceHeaders: (string * string) list -> unit + method removeHeader: name:string -> unit + 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 paramAll: ?meth:meth -> string -> string list + method params: (string * string) list + method params_GET: (string * string) list + method params_POST: (string * string) list + + end + +class type response = object + + inherit message + method code: int method setCode: int -> unit method status: status @@ -119,25 +209,15 @@ class type response = 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 contents: string - method setContents: string -> unit - method contentsBuf: Buffer.t - method setContentsBuf: Buffer.t -> unit - method addContents: string -> unit - method addContentsBuf: Buffer.t -> unit - method addHeader: name:string -> value:string -> unit + method addBasicHeaders: unit - method replaceHeader: name:string -> value:string -> unit - method removeHeader: name:string -> unit - method hasHeader: name:string -> bool - method header: name:string -> string - method headers: (string * string) list method contentType: string method setContentType: string -> unit method contentEncoding: string @@ -148,14 +228,19 @@ class type response = method setExpires: string -> unit method server: string method setServer: string -> unit - method toString: string - method serialize: out_channel -> unit + end -class type request = + +class type connection = object - method uri: string - method path: string - method param: string -> string - method paramAll: string -> string list - method params: (string * string) list + method getRequest: request option + method respond_with: response -> unit + method close: unit + end + +class type daemon = + object + method accept: connection + method getRequest: request * connection end +