mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 11:45:36 -05:00
Merge branch 'c-cube:master' into master
This commit is contained in:
commit
dc7fb3b87f
3 changed files with 7 additions and 8 deletions
|
|
@ -82,8 +82,8 @@ let vfs_of_dir (top:string) : vfs =
|
||||||
let contains f = Sys.file_exists (top // f)
|
let contains f = Sys.file_exists (top // f)
|
||||||
let list_dir f = Sys.readdir (top // f)
|
let list_dir f = Sys.readdir (top // f)
|
||||||
let read_file_content f =
|
let read_file_content f =
|
||||||
let ic = open_in_bin (top // f) in
|
let ic = Unix.(openfile (top // f) [O_RDONLY] 0) in
|
||||||
Tiny_httpd_stream.of_chan ic
|
Tiny_httpd_stream.of_fd ic
|
||||||
let create f =
|
let create f =
|
||||||
let oc = open_out_bin (top // f) in
|
let oc = open_out_bin (top // f) in
|
||||||
let write = output oc in
|
let write = output oc in
|
||||||
|
|
@ -398,4 +398,3 @@ module Embedded_fs = struct
|
||||||
end in (module M)
|
end in (module M)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ module Request = struct
|
||||||
} in
|
} in
|
||||||
Ok (Some req)
|
Ok (Some req)
|
||||||
with
|
with
|
||||||
| End_of_file | Sys_error _ -> Ok None
|
| End_of_file | Sys_error _ | Unix.Unix_error _ -> Ok None
|
||||||
| Bad_req (c,s) -> Error (c,s)
|
| Bad_req (c,s) -> Error (c,s)
|
||||||
| e ->
|
| e ->
|
||||||
Error (400, Printexc.to_string e)
|
Error (400, Printexc.to_string e)
|
||||||
|
|
|
||||||
|
|
@ -120,13 +120,13 @@ let of_string s : t =
|
||||||
of_bytes (Bytes.unsafe_of_string s)
|
of_bytes (Bytes.unsafe_of_string s)
|
||||||
|
|
||||||
let with_file ?buf_size file f =
|
let with_file ?buf_size file f =
|
||||||
let ic = open_in file in
|
let ic = Unix.(openfile file [O_RDONLY] 0) in
|
||||||
try
|
try
|
||||||
let x = f (of_chan ?buf_size ic) in
|
let x = f (of_fd ?buf_size ic) in
|
||||||
close_in ic;
|
Unix.close ic;
|
||||||
x
|
x
|
||||||
with e ->
|
with e ->
|
||||||
close_in_noerr ic;
|
Unix.close ic;
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
let read_all ?(buf=Buf.create()) (self:t) : string =
|
let read_all ?(buf=Buf.create()) (self:t) : string =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue