From e69f1b7c8c5193034c50a049d2f8ec0a2d209cb8 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 21 Feb 2024 22:06:24 -0500 Subject: [PATCH] feat dir: only read content of regular files no need to look into sockets, pipes, etc. --- src/Tiny_httpd_dir.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Tiny_httpd_dir.ml b/src/Tiny_httpd_dir.ml index 75c1062b..03adecb3 100644 --- a/src/Tiny_httpd_dir.ml +++ b/src/Tiny_httpd_dir.ml @@ -94,8 +94,12 @@ let vfs_of_dir (top : string) : vfs = let list_dir f = Sys.readdir (top // f) let read_file_content f = - let ic = Unix.(openfile (top // f) [ O_RDONLY ] 0) in - Tiny_httpd_stream.of_fd_close_noerr ic + let fpath = top // f in + match Unix.stat fpath with + | { st_kind = Unix.S_REG; _ } -> + let ic = Unix.(openfile fpath [ O_RDONLY ] 0) in + Tiny_httpd_stream.of_fd_close_noerr ic + | _ -> failwith (Printf.sprintf "not a regular file: %S" f) let create f = let oc = open_out_bin (top // f) in