(* as above but for OO version (Http_parser.parse_request') *)
let safe_parse_request' = wrap_parse_request_w_safety parse_request'
+let chdir_to_document_root = function (* chdir to document root *)
+ | Some dir -> Sys.chdir dir
+ | None -> ()
+
(* TODO support also chroot to 'root', not only chdir *)
(* curried request *)
let start
?(addr = default_addr) ?(port = default_port)
?(timeout = Some default_timeout) ?(mode = default_mode) ?root callback
=
- (match root with (* chdir to document root *)
- | Some dir -> Sys.chdir dir
- | None -> ());
- let sockaddr = Http_misc.build_sockaddr ~addr ~port in
+ chdir_to_document_root root;
+ let sockaddr = Http_misc.build_sockaddr (addr, port) in
let daemon_callback inchan outchan =
try
let (path, parameters) = safe_parse_request inchan outchan in
?(timeout = Some default_timeout) ?(mode = default_mode) ?root callback
=
let wrapper path params outchan =
- let req = new Http_request.request ~path ~params in
+ let clisockaddr = Http_misc.peername_of_out_channel outchan in
+ let req = new Http_request.request ~path ~params ~clisockaddr in
callback req outchan
in
match root with
object (self)
val suck =
- Http_tcp_server.init_socket (Http_misc.build_sockaddr ~addr ~port)
+ Http_tcp_server.init_socket (Http_misc.build_sockaddr (addr, port))
method accept =
let (cli_suck, cli_sockaddr) = Unix.accept suck in (* may block *)