Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware.static: etag_of_fname should return Lwt.t ?! #265

Open
pkel opened this issue Mar 20, 2021 · 4 comments
Open

Middleware.static: etag_of_fname should return Lwt.t ?! #265

pkel opened this issue Mar 20, 2021 · 4 comments

Comments

@pkel
Copy link
Contributor

pkel commented Mar 20, 2021

Hi and thanks for your efforts on this project. Opium is really useful to get a web app running quickly.

I tried to enable caching for static files served with the static and static_unix middlewares. I have two use cases:

  1. static: check last modification of file in Irmin/Git store, use commit hash as etag.
  2. static_unix: derive etag from Lwt_unix.stat st_mtime or similar.

Unfortunately, the etag_of_fname argument is of type string -> string option. I'd prefer string -> string option Lwt.t. Are you interested in a PR changing the type? I could also extend the static_unix middleware such that it defaults to mtime-based etags.

@tmattio
Copy link
Collaborator

tmattio commented Mar 22, 2021

Hi @pkel!

Are you interested in a PR changing the type?

Sure, that makes sense, I'd be happy to merge such a PR

I could also extend the static_unix middleware such that it defaults to mtime-based etags.

Could you clarify what you have in mind?

I'm not sure what the spec has to say about it, but I've only seen Etag generated from content hashes.

@pkel
Copy link
Contributor Author

pkel commented Mar 22, 2021

Could you clarify what you have in mind?

I'd go for "a hash of the last modification timestamp" mentioned here:
https://en.wikipedia.org/wiki/HTTP_ETag#ETag_generation

I think this should be enough for static files served from a UNIX file system.

@tmattio
Copy link
Collaborator

tmattio commented Mar 22, 2021

I'd go for "a hash of the last modification timestamp" mentioned here

We could provide this as an option, something like ?etag_strategy:[> `Content_hash | `Modification_timestamp ] ? I'd be fine with having the timestamp by default, but I can imagine use cases where users would like to use a different generation strategy

@pkel
Copy link
Contributor Author

pkel commented Mar 22, 2021

What about keeping the optional ?etag_of_fname:(string -> string option Lwt.t) and doing the timestamp thing if ~etag_of_fname is not given? This way we would not break existing use-cases, e.g. someone tracking the etags in a hash-table.

pkel added a commit to pkel/opium that referenced this issue Mar 22, 2021
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 rgrinberg#265.
tmattio pushed a commit that referenced this issue Apr 29, 2021
* 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
anuragsoni pushed a commit that referenced this issue Nov 20, 2021
* 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
pkel added a commit to pkel/ffr-cms that referenced this issue Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants