"Connection: " ^ (if keep_alive then "keep-alive" else "close");
"Cache-Control: no-cache, no-store" ]
-let http_200_ok_with_content length ?(version="HTTP/1.1") ?(keep_alive=true) () =
- [ version^" 200 OK";
+let http_200_ok_with_content length ?(version="1.1") ?(keep_alive=true) () =
+ [ Printf.sprintf "HTTP/%s 200 OK" version;
"Connection: " ^ (if keep_alive then "keep-alive" else "close");
"Content-Length: "^(Int64.to_string length);
"Cache-Control: no-cache, no-store" ]
(default "" x.content_type)
(default "" x.user_agent)
+let http_request_request ?(version="1.0") ?(keep_alive=false) ?cookie ?length ~user_agent meth host path =
+{ nullreq with
+ version = version;
+ close = not keep_alive;
+ cookie = Opt.default [] cookie;
+ content_length = length;
+ user_agent = Some user_agent;
+ m = meth;
+ uri = path;
+ headers = [ Printf.sprintf "Host: %s" host ];
+}
+
let http_request ?(version="1.0") ?(keep_alive=false) ?cookie ?length ~user_agent meth host path =
let cookie = default [] (may (fun x -> [ "Cookie: " ^ (print_keyvalpairs x) ]) cookie) in
let content_length = default [] (may (fun l -> [ "Content-Length: "^(Int64.to_string l)]) length) in
val http_request : ?version:string -> ?keep_alive:bool -> ?cookie:((string*string) list) -> ?length:(int64) -> user_agent:(string) -> method_t -> string -> string -> string list
+val http_request_request : ?version:string -> ?keep_alive:bool -> ?cookie:((string*string) list) -> ?length:(int64) -> user_agent:(string) -> method_t -> string -> string -> request
+
val http_403_forbidden : string list
val http_200_ok : ?version:string -> ?keep_alive:bool -> unit -> string list
try
let (maj,min) = Scanf.sscanf req.version "HTTP/%d.%d" (fun a b -> (a,b)) in
match (maj,min) with
- (1,0) -> "HTTP/1.0"
- | _ -> "HTTP/1.1"
- with _ -> "HTTP/1.1"
+ (1,0) -> "1.0"
+ | _ -> "1.1"
+ with _ -> "1.1"
let response_fct req ?(hdrs=[]) s (response_length: int64) (write_response_to_fd_fn: Unix.file_descr -> unit) =
let version = get_return_version req in
| None -> []
| Some ty -> [ "Content-Type: " ^ ty ]
in
- headers s (http_200_ok_with_content size ~version:"HTTP/1.1" ~keep_alive:true ()
+ headers s (http_200_ok_with_content size ~version:"1.1" ~keep_alive:true ()
@ mime_header);
let buffer = String.make 65536 '\000' in
let ic = open_in file in