mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
feat: optional dep on magic-mime for http_of_dir
This commit is contained in:
parent
0d1bccfd1b
commit
d9b3731207
8 changed files with 13 additions and 13 deletions
0
.gitmodules
vendored
0
.gitmodules
vendored
|
|
@ -15,6 +15,7 @@
|
|||
(tags (http thread server tiny_httpd http_of_dir simplehttpserver))
|
||||
(depopts
|
||||
logs
|
||||
magic-mime
|
||||
(mtime (>= 2.0)))
|
||||
(depends
|
||||
seq
|
||||
|
|
|
|||
|
|
@ -310,18 +310,8 @@ let add_vfs_ ~on_fs ~top ~config ~vfs:((module VFS : VFS) as vfs) ~prefix server
|
|||
[ "Content-Type", "text/javascript" ]
|
||||
else if on_fs then (
|
||||
(* call "file" util *)
|
||||
try
|
||||
let p =
|
||||
Unix.open_process_in
|
||||
(Printf.sprintf "file -i -b %S" (top // path))
|
||||
in
|
||||
finally_
|
||||
~h:(fun p -> ignore @@ Unix.close_process_in p)
|
||||
p
|
||||
(fun p ->
|
||||
try [ "Content-Type", String.trim (input_line p) ]
|
||||
with _ -> [])
|
||||
with _ -> []
|
||||
let ty = Mime_.mime_of_path (top // path) in
|
||||
[ "content-type", ty ]
|
||||
) else
|
||||
[]
|
||||
in
|
||||
|
|
|
|||
6
src/dune
6
src/dune
|
|
@ -1,9 +1,13 @@
|
|||
(library
|
||||
(name tiny_httpd)
|
||||
(public_name tiny_httpd)
|
||||
(private_modules mime_)
|
||||
(libraries threads seq unix
|
||||
(select mime_.ml from
|
||||
(magic-mime -> mime_.magic.ml)
|
||||
( -> mime_.dummy.ml))
|
||||
(select Tiny_httpd_log.ml from
|
||||
(logs -> Tiny_httpd_log.logs.ml)
|
||||
(logs logs.fmt fmt.tty -> Tiny_httpd_log.logs.ml)
|
||||
(-> Tiny_httpd_log.default.ml)))
|
||||
(wrapped false))
|
||||
|
||||
|
|
|
|||
1
src/mime_.dummy.ml
Normal file
1
src/mime_.dummy.ml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let mime_of_path _ = "application/octet-stream"
|
||||
1
src/mime_.magic.ml
Normal file
1
src/mime_.magic.ml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let mime_of_path s = Magic_mime.lookup s
|
||||
2
src/mime_.mli
Normal file
2
src/mime_.mli
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
val mime_of_path : string -> string
|
||||
|
|
@ -24,6 +24,7 @@ depends: [
|
|||
]
|
||||
depopts: [
|
||||
"logs"
|
||||
"magic-mime"
|
||||
"mtime" {>= "2.0"}
|
||||
]
|
||||
build: [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue