From 7e236058f70d69e975a51240a28bf5575758f4fb Mon Sep 17 00:00:00 2001 From: craff Date: Sun, 19 Dec 2021 00:58:03 -1000 Subject: [PATCH] remove mem cache ... not really usefull to gain speed --- src/Tiny_httpd_dir.ml | 16 +--------------- src/Tiny_httpd_dir.mli | 1 - tests/dl-out.expect | 5 ++++- tests/download_chunked.sh | 13 +++++++++++-- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Tiny_httpd_dir.ml b/src/Tiny_httpd_dir.ml index 55b70d3a..f659bbaa 100644 --- a/src/Tiny_httpd_dir.ml +++ b/src/Tiny_httpd_dir.ml @@ -7,7 +7,6 @@ type dir_behavior = type config = { mutable download: bool; - mutable mem_cache: bool; mutable dir_behavior: dir_behavior; mutable delete: bool; mutable upload: bool; @@ -16,7 +15,6 @@ type config = { let default_config () : config = { download=true - ; mem_cache=false ; dir_behavior=Forbidden ; delete=false ; upload=false @@ -43,7 +41,7 @@ let header_html = "Content-Type", "text/html" let (//) = Filename.concat let encode_path s = U.percent_encode ~skip:(function '/' -> true|_->false) s -let decode_path s = match U.percent_decode s with Some s->s | None -> s +let _decode_path s = match U.percent_decode s with Some s->s | None -> s let is_hidden s = String.length s>0 && s.[0] = '.' @@ -164,8 +162,6 @@ let add_dir_path ~config ~dir ~prefix server = (fun _ _ -> S.Response.make_raw ~code:405 "upload not allowed"); ); - let cache = Hashtbl.create 101 in - if config.download then ( S.add_route_handler server ~meth:`GET S.Route.(exact_path prefix (rest_of_path_urlencoded)) @@ -175,13 +171,6 @@ let add_dir_path ~config ~dir ~prefix server = try Printf.sprintf "mtime: %f" (Unix.stat full_path).Unix.st_mtime with _ -> S.Response.fail_raise ~code:403 "Cannot access file" ) in - try - if not config.mem_cache then raise Not_found; - let (ans, mtime0) = Hashtbl.find cache path in - if mtime <> mtime0 then raise Not_found; - ans - with Not_found -> - let ans = if contains_dot_dot full_path then ( S.Response.fail ~code:403 "Path is forbidden"; ) else if not (Sys.file_exists full_path) then ( @@ -231,9 +220,6 @@ let add_dir_path ~config ~dir ~prefix server = ~code:200 (S.Byte_stream.of_chan ic) with e -> S.Response.fail ~code:500 "error while reading file: %s" (Printexc.to_string e)) - in - Hashtbl.replace cache path (ans,mtime); - ans ) ) else ( S.add_route_handler server ~meth:`GET diff --git a/src/Tiny_httpd_dir.mli b/src/Tiny_httpd_dir.mli index 57e6dcb2..a5cbf213 100644 --- a/src/Tiny_httpd_dir.mli +++ b/src/Tiny_httpd_dir.mli @@ -4,7 +4,6 @@ type dir_behavior = type config = { mutable download: bool; - mutable mem_cache: bool; mutable dir_behavior: dir_behavior; mutable delete: bool; mutable upload: bool; diff --git a/tests/dl-out.expect b/tests/dl-out.expect index d0e79081..fb1769c9 100644 --- a/tests/dl-out.expect +++ b/tests/dl-out.expect @@ -1,2 +1,5 @@ serve directory . on http://127.0.0.1:8084 - 0 0 52428800 data2 + 0 0 52428800 data21 + 0 0 52428800 data22 + 0 0 52428800 data23 + 0 0 157286400 total diff --git a/tests/download_chunked.sh b/tests/download_chunked.sh index 2fc4e3c5..caa9a8b2 100755 --- a/tests/download_chunked.sh +++ b/tests/download_chunked.sh @@ -7,8 +7,17 @@ PID=$! sleep 0.1 -curl -N "http://localhost:${PORT}/foo_50" -o data2 \ +echo download1 1>&2 +curl -N "http://localhost:${PORT}/foo_50" -o data21 \ + -H 'Tranfer-encoding: chunked' + +echo download2 1>&2 +curl -N "http://localhost:${PORT}/foo_50" -o data22 \ + -H 'Tranfer-encoding: chunked' + +echo download3 1>&2 +curl -N "http://localhost:${PORT}/foo_50" -o data23 \ -H 'Tranfer-encoding: chunked' kill $PID -wc data2 +wc data21 data22 data23