]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/ocaml-http/http_response.ml
added support for "ancient" HTTP requests like "GET /foo"
[helm.git] / helm / DEVEL / ocaml-http / http_response.ml
index 913c227551acd60a960cb42a5c60ee428ec8ff3b..6fc3213254114f63a76a30ca47ec236b327b42a3 100644 (file)
@@ -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