mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
parent
912c7b1fd7
commit
f08406c1ae
3 changed files with 12 additions and 14 deletions
|
|
@ -204,10 +204,9 @@ let add_dir_path ~config ~dir ~prefix server =
|
|||
S.Response.make_raw ~code:405 "listing dir not allowed"
|
||||
) else (
|
||||
try
|
||||
let fd = Unix.(openfile full_path [O_RDONLY] 0) in
|
||||
let len = stat.Unix.st_size in
|
||||
let bs = Bigstring_unix.map_file_descr fd len in
|
||||
Gc.finalise (fun _ -> Unix.close fd) bs;
|
||||
let bs = Bigstring_unix.with_map_file ~flags:[Open_rdonly] full_path
|
||||
(fun s -> s)
|
||||
in
|
||||
let mime_type =
|
||||
if Filename.extension full_path = ".css" then (
|
||||
["Content-Type", "text/css"]
|
||||
|
|
@ -225,7 +224,9 @@ let add_dir_path ~config ~dir ~prefix server =
|
|||
~headers:(mime_type@["Etag", mtime_str])
|
||||
~code:200 bs
|
||||
with e ->
|
||||
S.Response.fail ~code:500 "error while reading file: %s" (Printexc.to_string e)))) else (
|
||||
S.Response.fail ~code:500 "error while reading file: %s" (Printexc.to_string e))
|
||||
)
|
||||
) else (
|
||||
S.add_route_handler server ~meth:`GET
|
||||
S.Route.(exact_path prefix (string @/ return))
|
||||
(fun _ _ -> S.Response.make_raw ~code:405 "download not allowed");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,2 @@
|
|||
serve directory . on http://127.0.0.1:8084
|
||||
0 0 52428800 data21
|
||||
0 0 52428800 data22
|
||||
0 0 52428800 data23
|
||||
0 0 157286400 total
|
||||
0 0 52428800 data2
|
||||
|
|
|
|||
|
|
@ -8,16 +8,16 @@ PID=$!
|
|||
sleep 0.1
|
||||
|
||||
echo download1 1>&2
|
||||
curl -N "http://localhost:${PORT}/foo_50" -o data21 \
|
||||
curl -N "http://localhost:${PORT}/foo_50" -o data2 \
|
||||
-H 'Tranfer-encoding: chunked'
|
||||
|
||||
echo download2 1>&2
|
||||
curl -N "http://localhost:${PORT}/foo_50" -o data22 \
|
||||
curl -N "http://localhost:${PORT}/foo_50" -o data2 \
|
||||
-H 'Tranfer-encoding: chunked'
|
||||
|
||||
echo download3 1>&2
|
||||
curl -N "http://localhost:${PORT}/foo_50" -o data23 \
|
||||
curl -N "http://localhost:${PORT}/foo_50" -o data2 \
|
||||
-H 'Tranfer-encoding: chunked'
|
||||
|
||||
kill $PID
|
||||
wc data21 data22 data23
|
||||
wc data2
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue