mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
fix(http_of_dir): do not url-encode paths with /
This commit is contained in:
parent
2ed9131bdc
commit
c6d5c9a40f
1 changed files with 4 additions and 4 deletions
|
|
@ -39,7 +39,7 @@ let human_size (x:int) : string =
|
||||||
let header_html = "Content-Type", "text/html"
|
let header_html = "Content-Type", "text/html"
|
||||||
let (//) = Filename.concat
|
let (//) = Filename.concat
|
||||||
|
|
||||||
let encode_path s = U.percent_encode s
|
let encode_path s = U.percent_encode ~skip:(function '/' -> true|_->false) s
|
||||||
|
|
||||||
let is_hidden s = String.length s>0 && s.[0] = '.'
|
let is_hidden s = String.length s>0 && s.[0] = '.'
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ let serve ~config (dir:string) : _ result =
|
||||||
dir (if S.is_ipv6 server then "[%s]" else "%s") config.addr config.port;
|
dir (if S.is_ipv6 server then "[%s]" else "%s") config.addr config.port;
|
||||||
if config.delete then (
|
if config.delete then (
|
||||||
S.add_route_handler server ~meth:`DELETE
|
S.add_route_handler server ~meth:`DELETE
|
||||||
S.Route.(string_urlencoded @/ return)
|
S.Route.rest
|
||||||
(fun path _req ->
|
(fun path _req ->
|
||||||
if contains_dot_dot path then (
|
if contains_dot_dot path then (
|
||||||
S.Response.fail_raise ~code:403 "invalid path in delete"
|
S.Response.fail_raise ~code:403 "invalid path in delete"
|
||||||
|
|
@ -131,7 +131,7 @@ let serve ~config (dir:string) : _ result =
|
||||||
);
|
);
|
||||||
if config.upload then (
|
if config.upload then (
|
||||||
S.add_route_handler_stream server ~meth:`PUT
|
S.add_route_handler_stream server ~meth:`PUT
|
||||||
S.Route.(string_urlencoded @/ return)
|
S.Route.rest
|
||||||
~accept:(fun req ->
|
~accept:(fun req ->
|
||||||
match S.Request.get_header_int req "Content-Length" with
|
match S.Request.get_header_int req "Content-Length" with
|
||||||
| Some n when n > config.max_upload_size ->
|
| Some n when n > config.max_upload_size ->
|
||||||
|
|
@ -161,7 +161,7 @@ let serve ~config (dir:string) : _ result =
|
||||||
(fun _ _ -> S.Response.make_raw ~code:405 "upload not allowed");
|
(fun _ _ -> S.Response.make_raw ~code:405 "upload not allowed");
|
||||||
);
|
);
|
||||||
S.add_route_handler server ~meth:`GET
|
S.add_route_handler server ~meth:`GET
|
||||||
S.Route.(string_urlencoded @/ return)
|
S.Route.rest
|
||||||
(fun path req ->
|
(fun path req ->
|
||||||
let full_path = dir // path in
|
let full_path = dir // path in
|
||||||
let mtime = lazy (
|
let mtime = lazy (
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue