(*
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;;
(* "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
| 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 *)
| 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
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