X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Focaml-http%2Fhttp_daemon.ml;h=8b71acbc8a882f183c347198c88973731f982aae;hb=d2c60bae1c4badba0a0f29e3fd2faed6d3a1869e;hp=5b621bf55f8a6d176aa2565e21baa10bd590ef75;hpb=e8466faa2922f4bb480a87e88435bf0ddc26a747;p=helm.git diff --git a/helm/DEVEL/ocaml-http/http_daemon.ml b/helm/DEVEL/ocaml-http/http_daemon.ml index 5b621bf55..8b71acbc8 100644 --- a/helm/DEVEL/ocaml-http/http_daemon.ml +++ b/helm/DEVEL/ocaml-http/http_daemon.ml @@ -184,9 +184,11 @@ let respond_forbidden ~url ?(version = http_version) outchan = send_empty_response "Daemon.respond_permission_denied" ~body:"" () ~version ~code:403 outchan -let send_file ?name ?file outchan = +(* let send_file ?name ?file outchan = *) +let send_file ~src outchan = let buflen = 1024 in let buf = String.make buflen ' ' in +(* let (file, cleanup) = (match (name, file) with | Some n, None -> (* if we open the file, we close it before returning *) @@ -196,6 +198,14 @@ let send_file ?name ?file outchan = | _ -> (* TODO use some static type checking *) failwith "Daemon.send_file: either name or file must be given") in +*) + let (file, cleanup) = + match src with + | FileSrc fname -> (* if we open the file, we close it before returning *) + let f = open_in fname in + f, (fun () -> close_in f) + | InChanSrc inchan -> inchan, ignore + in try while true do let bytes = input file buf 0 buflen in @@ -254,7 +264,7 @@ let respond_file ~fname ?(version = http_version) outchan = ~value:(string_of_int (Http_misc.filesize fname)) outchan; send_CRLF outchan; - send_file ~file outchan; + send_file ~src:(InChanSrc file) outchan; close_in file end with @@ -301,7 +311,7 @@ let rec wrap_parse_request_w_safety parse_function inchan outchan = "
\nwhile received request 1st line was:
\n" ^ req) outchan; raise Again - | (Unsupported_method meth) as e -> + | (Invalid_HTTP_method meth) as e -> debug_print (pp_parse_exc e); respond_error ~code:501 @@ -312,7 +322,7 @@ let rec wrap_parse_request_w_safety parse_function inchan outchan = debug_print (pp_parse_exc e); respond_error ~code:400 ~body:("Malformed URL: '" ^ uri ^ "'") outchan; raise Again - | (Unsupported_HTTP_version version) as e -> + | (Invalid_HTTP_version version) as e -> debug_print (pp_parse_exc e); respond_error ~code:505 @@ -353,9 +363,13 @@ let chdir_to_document_root = function (* chdir to document root *) let server_of_mode = function | `Single -> Http_tcp_server.simple - | `Fork -> Http_tcp_server.ocaml_builtin + | `Fork -> Http_tcp_server.fork | `Thread -> Http_tcp_server.thread + (* TODO what happens when a Quit exception is raised by a callback? Do other + callbacks keep on living until the end or are them all killed immediatly? + The right semantics should obviously be the first one *) + (* TODO support also chroot to 'root', not only chdir *) (* curried request *) let start