mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
code cleanup
This commit is contained in:
parent
bfee36572c
commit
bf2bf6832d
2 changed files with 73 additions and 82 deletions
|
|
@ -3,7 +3,7 @@ module U = Tiny_httpd_util
|
|||
module Pf = Printf
|
||||
|
||||
type dir_behavior =
|
||||
Index | Lists | IndexAndLists | Forbidden
|
||||
| Index | Lists | Index_or_lists | Forbidden
|
||||
|
||||
type config = {
|
||||
mutable download: bool;
|
||||
|
|
@ -100,15 +100,6 @@ let finally_ ~h x f =
|
|||
h x;
|
||||
raise e
|
||||
|
||||
(* TODO
|
||||
let wdays = [|"Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"|]
|
||||
let date_of_time (f:float) : string =
|
||||
let open Unix in
|
||||
let t = Unix.gmtime f in
|
||||
Printf.sprintf "%s, %02d %d %d %d:%d:%d GMT"
|
||||
wdays.(t.tm_yday) t.tm_mday t.tm_mon t.tm_year t.tm_hour t.tm_min t.tm_sec
|
||||
*)
|
||||
|
||||
let add_dir_path ~config ~dir ~prefix server =
|
||||
|
||||
if config.delete then (
|
||||
|
|
@ -183,14 +174,14 @@ let add_dir_path ~config ~dir ~prefix server =
|
|||
let parent = Filename.(dirname path) in
|
||||
let parent = if parent <> path then Some parent else None in
|
||||
match config.dir_behavior with
|
||||
| Index | IndexAndLists when
|
||||
| Index | Index_or_lists when
|
||||
Sys.file_exists (full_path // "index.html") ->
|
||||
(* redirect using path, not full path *)
|
||||
let new_path = "/" // path // "index.html" in
|
||||
S._debug (fun k->k "redirect to `%s`" new_path);
|
||||
S.Response.make_raw ~code:301 ""
|
||||
~headers:S.Headers.(empty |> set "location" new_path)
|
||||
| Lists | IndexAndLists ->
|
||||
| Lists | Index_or_lists ->
|
||||
let body = html_list_dir ~top:dir path ~parent in
|
||||
S.Response.make_string
|
||||
~headers:[header_html; "ETag", Lazy.force mtime]
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ let main () =
|
|||
" automatically redirect to index.html if present";
|
||||
"--list-dir", Unit (fun () -> config.dir_behavior <- Lists),
|
||||
" automatically lists directory";
|
||||
"--index-and-list", Unit (fun () -> config.dir_behavior <- IndexAndLists),
|
||||
"--index-and-list", Unit (fun () -> config.dir_behavior <- Index_or_lists),
|
||||
" automatically redirect to index.html or lists directory";
|
||||
"--delete", Unit (fun () -> config.delete <- true), " enable `delete` on files";
|
||||
"--no-delete", Unit (fun () -> config.delete <- false), " disable `delete` on files";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue