mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 19:55:36 -05:00
remove mem cache ... not really usefull to gain speed
This commit is contained in:
parent
6dceabdd6c
commit
7e236058f7
4 changed files with 16 additions and 19 deletions
|
|
@ -7,7 +7,6 @@ type dir_behavior =
|
||||||
|
|
||||||
type config = {
|
type config = {
|
||||||
mutable download: bool;
|
mutable download: bool;
|
||||||
mutable mem_cache: bool;
|
|
||||||
mutable dir_behavior: dir_behavior;
|
mutable dir_behavior: dir_behavior;
|
||||||
mutable delete: bool;
|
mutable delete: bool;
|
||||||
mutable upload: bool;
|
mutable upload: bool;
|
||||||
|
|
@ -16,7 +15,6 @@ type config = {
|
||||||
|
|
||||||
let default_config () : config =
|
let default_config () : config =
|
||||||
{ download=true
|
{ download=true
|
||||||
; mem_cache=false
|
|
||||||
; dir_behavior=Forbidden
|
; dir_behavior=Forbidden
|
||||||
; delete=false
|
; delete=false
|
||||||
; upload=false
|
; upload=false
|
||||||
|
|
@ -43,7 +41,7 @@ let header_html = "Content-Type", "text/html"
|
||||||
let (//) = Filename.concat
|
let (//) = Filename.concat
|
||||||
|
|
||||||
let encode_path s = U.percent_encode ~skip:(function '/' -> true|_->false) s
|
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] = '.'
|
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");
|
(fun _ _ -> S.Response.make_raw ~code:405 "upload not allowed");
|
||||||
);
|
);
|
||||||
|
|
||||||
let cache = Hashtbl.create 101 in
|
|
||||||
|
|
||||||
if config.download then (
|
if config.download then (
|
||||||
S.add_route_handler server ~meth:`GET
|
S.add_route_handler server ~meth:`GET
|
||||||
S.Route.(exact_path prefix (rest_of_path_urlencoded))
|
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
|
try Printf.sprintf "mtime: %f" (Unix.stat full_path).Unix.st_mtime
|
||||||
with _ -> S.Response.fail_raise ~code:403 "Cannot access file"
|
with _ -> S.Response.fail_raise ~code:403 "Cannot access file"
|
||||||
) in
|
) 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 (
|
if contains_dot_dot full_path then (
|
||||||
S.Response.fail ~code:403 "Path is forbidden";
|
S.Response.fail ~code:403 "Path is forbidden";
|
||||||
) else if not (Sys.file_exists full_path) then (
|
) 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)
|
~code:200 (S.Byte_stream.of_chan ic)
|
||||||
with e ->
|
with e ->
|
||||||
S.Response.fail ~code:500 "error while reading file: %s" (Printexc.to_string e))
|
S.Response.fail ~code:500 "error while reading file: %s" (Printexc.to_string e))
|
||||||
in
|
|
||||||
Hashtbl.replace cache path (ans,mtime);
|
|
||||||
ans
|
|
||||||
)
|
)
|
||||||
) else (
|
) else (
|
||||||
S.add_route_handler server ~meth:`GET
|
S.add_route_handler server ~meth:`GET
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ type dir_behavior =
|
||||||
|
|
||||||
type config = {
|
type config = {
|
||||||
mutable download: bool;
|
mutable download: bool;
|
||||||
mutable mem_cache: bool;
|
|
||||||
mutable dir_behavior: dir_behavior;
|
mutable dir_behavior: dir_behavior;
|
||||||
mutable delete: bool;
|
mutable delete: bool;
|
||||||
mutable upload: bool;
|
mutable upload: bool;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,5 @@
|
||||||
serve directory . on http://127.0.0.1:8084
|
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
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,17 @@ PID=$!
|
||||||
|
|
||||||
sleep 0.1
|
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'
|
-H 'Tranfer-encoding: chunked'
|
||||||
|
|
||||||
kill $PID
|
kill $PID
|
||||||
wc data2
|
wc data21 data22 data23
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue