headers.go 488 B

1234567891011121314151617181920
  1. package internal
  2. import (
  3. "net/http"
  4. "github.com/TecharoHQ/anubis"
  5. )
  6. // UnchangingCache sets the Cache-Control header to cache a response for 1 year if
  7. // and only if the application is compiled in "release" mode by Docker.
  8. func UnchangingCache(h http.Handler) http.Handler {
  9. if anubis.Version == "devel" {
  10. return h
  11. }
  12. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  13. w.Header().Set("Cache-Control", "public, max-age=31536000")
  14. h.ServeHTTP(w, r)
  15. })
  16. }