akka/akka-http

Adding a default cache-control header for routes served from FileAndResourceDirectives

Open

#2 273 ouverte le 7 nov. 2018

Voir sur GitHub
 (2 commentaires) (1 réaction) (0 assignés)Scala (598 forks)batch import
1 - triagedhelp wantedt:routingt:server

Métriques du dépôt

Stars
 (1 311 stars)
Métriques de merge PR
 (Merge moyen 1j 10h) (2 PRs mergées en 30 j)

Description

FileAndResourceDirectives provides a lot of helpful functions to serve static assets from file system. Currently it adds Etag and Last-Modified response header to help with caching on browsers. I think we should also add a default Cache-Control response header. Because without a cache-control header, browsers are free to choose their own caching heuristic and that may result in serving stale assets from cache and some weird behaviours.

And, also I think the default cache-control header should be Cache-Control: must-revalidate, because this will trigger a cache revalidation on every request (If the requested asset is not changed, browser will get 304 - Not modified and served from cache)

Current workaround is to wrap getFromFile calls under respondWithHeader functions. It would be nice, if the library provides this to us by default.

Guide contributeur