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

Add caching capabilities to static middleware #76

Merged
merged 1 commit into from
Apr 13, 2018

Conversation

mattjbray
Copy link
Contributor

This PR adds an optional etag_of_fname argument to Middleware.static. When provided, the middleware will add the ETag header to responses.

If the request includes the If-None-Match header and the etag_of_fname argument is provided, the middleware will check the ETag and respond with 304 Not Modified if it matches. (Note that it will do this even if the file no longer exists in the filesystem).

This PR also adds an optional headers argument. Using this the user can e.g. specify a Cache-Control policy.

Aside: it looks like Cohttp_lwt_unix.Server.respond_file now sets the Content-Type header using Magic_mime. Should we remove that from this middleware?

@rgrinberg
Copy link
Owner

Aside: it looks like Cohttp_lwt_unix.Server.respond_file now sets the Content-Type header using Magic_mime. Should we remove that from this middleware?

Indeed.

Thanks for the PR.

@rgrinberg rgrinberg merged commit 2fc6e78 into rgrinberg:master Apr 13, 2018
@mattjbray mattjbray deleted the static-middleware-caching branch April 13, 2018 15:57
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Jan 4, 2019
CHANGES:

- Switch to dune (rgrinberg/opium#88, anuragoni)

- Keep the "/" cookie default and expose all cookie directives (rgrinberg/opium#82,
  @actionshrimp)

- Do not assume base 64 encoding of cookies (rgrinberg/opium#74, @malthe)

- Add caching capabilities to middleware (rgrinberg/opium#76, @mattjbray)
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

Successfully merging this pull request may close these issues.

None yet

2 participants