X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Focaml-http%2Fhttp_daemon.ml;h=9e0507dd2b1a4135643cef76cdfa73b9864edbe8;hb=5325734bc2e4927ed7ec146e35a6f0f2b49f50c1;hp=6b2818ec1a6995b6460da5999cb634cf5d86fcab;hpb=56c392b11f3459075fec2498a3548efe26c9299a;p=helm.git diff --git a/helm/DEVEL/ocaml-http/http_daemon.ml b/helm/DEVEL/ocaml-http/http_daemon.ml index 6b2818ec1..9e0507dd2 100644 --- a/helm/DEVEL/ocaml-http/http_daemon.ml +++ b/helm/DEVEL/ocaml-http/http_daemon.ml @@ -26,11 +26,6 @@ open Http_types;; open Http_constants;; open Http_parser;; -let default_addr = "0.0.0.0" -let default_port = 80 -let default_timeout = 300 -let default_mode = `Fork - (** send raw data on outchan, flushing it afterwards *) let send_raw ~data outchan = output_string outchan data; @@ -184,9 +179,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 +193,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 +259,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 @@ -356,6 +361,10 @@ let server_of_mode = function | `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