-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Get ETag as LWT promise This commit changes the static middlewares' ETag argument from `?etag_of_fname:(string -> string option)` to `?etag_of_fname:(string -> string option Lwt.t)`. This change was proposed in #265. * Generate ETag from UNIX file system * Update CHANGES.md * ocamlformat my changes
- Loading branch information
1 parent
551015a
commit 73d16b8
Showing
6 changed files
with
36 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
let m ~local_path ?uri_prefix ?headers ?etag_of_fname () = | ||
let open Lwt.Syntax in | ||
open Lwt.Syntax | ||
|
||
let default_etag ~local_path fname = | ||
let fpath = Filename.concat local_path fname in | ||
let* exists = Lwt_unix.file_exists fpath in | ||
if exists | ||
then | ||
let* stat = Lwt_unix.stat fpath in | ||
let hash = | ||
Marshal.to_string stat.st_mtime [] | ||
|> Cstruct.of_string | ||
|> Mirage_crypto.Hash.digest `MD5 | ||
|> Cstruct.to_string | ||
|> Base64.encode_exn | ||
in | ||
Lwt.return_some hash | ||
else Lwt.return_none | ||
;; | ||
|
||
let m ~local_path ?uri_prefix ?headers ?(etag_of_fname = default_etag ~local_path) () = | ||
let read fname = | ||
let* body = Body.of_file (Filename.concat local_path fname) in | ||
match body with | ||
| None -> Lwt.return (Error `Not_found) | ||
| Some body -> Lwt.return (Ok body) | ||
in | ||
Middleware_static.m ~read ?uri_prefix ?headers ?etag_of_fname () | ||
Middleware_static.m ~read ?uri_prefix ?headers ~etag_of_fname () | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters