]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/ocaml-http/http_response.ml
ocaml 3.09 transition
[helm.git] / helm / DEVEL / ocaml-http / http_response.ml
index 913c227551acd60a960cb42a5c60ee428ec8ff3b..58308d30700ed217f3482727c1d6a46ef32cb180 100644 (file)
@@ -2,21 +2,21 @@
 (*
   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
 *)
 
 open Http_types;;
@@ -47,8 +47,10 @@ class response
     (* "version code reason_phrase" *)
   object (self)
 
+      (* note that response objects can't be created with a None version *)
     inherit
-      Http_message.message ~body ~headers ~version ~clisockaddr ~srvsockaddr
+      Http_message.message
+        ~body ~headers ~version:(Some version) ~clisockaddr ~srvsockaddr
 
     val mutable _code =
       match status with
@@ -56,6 +58,13 @@ class response
       | Some (s: Http_types.status) -> code_of_status s
     val mutable _reason: string option = None
 
+    method private getRealVersion =
+      match self#version with
+      | None ->
+          failwith ("Http_response.fstLineToString: " ^
+            "can't serialize an HTTP response with no HTTP version defined")
+      | Some v -> string_of_version v
+
     method code = _code
     method setCode c =
       ignore (status_of_code c);  (* sanity check on c *)
@@ -68,9 +77,8 @@ class response
       | Some r -> r
     method setReason r = _reason <- Some r
     method statusLine =
-      String.concat
-        " "
-        [string_of_version self#version; string_of_int self#code; self#reason]
+      String.concat " "
+        [self#getRealVersion; string_of_int self#code; self#reason]
     method setStatusLine s =
       try
         let subs = Pcre.extract ~rex:status_line_RE s in
@@ -104,11 +112,7 @@ class response
     method setServer s = self#replaceHeader "Server" s
 
     method private fstLineToString =
-      sprintf
-        "%s %d %s"
-        (string_of_version self#version)
-        self#code
-        self#reason
+      sprintf "%s %d %s" self#getRealVersion self#code self#reason
 
   end