X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Focaml-http%2Fhttp_response.ml;h=6fc3213254114f63a76a30ca47ec236b327b42a3;hb=9f60b3b0f4460aec52ec241037f6c475b421dd15;hp=913c227551acd60a960cb42a5c60ee428ec8ff3b;hpb=ca9cd0aeee0ce78a891f7f6091ca8704231a446d;p=helm.git diff --git a/helm/DEVEL/ocaml-http/http_response.ml b/helm/DEVEL/ocaml-http/http_response.ml index 913c22755..6fc321325 100644 --- a/helm/DEVEL/ocaml-http/http_response.ml +++ b/helm/DEVEL/ocaml-http/http_response.ml @@ -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