anubis/internal/headers.go
Xe Iaso 9923878c5c
initial import from /x/ monorepo
Signed-off-by: Xe Iaso <me@xeiaso.net>
2025-03-17 19:33:07 -04:00

20 lines
488 B
Go

package internal
import (
"net/http"
"github.com/TecharoHQ/anubis"
)
// UnchangingCache sets the Cache-Control header to cache a response for 1 year if
// and only if the application is compiled in "release" mode by Docker.
func UnchangingCache(h http.Handler) http.Handler {
if anubis.Version == "devel" {
return h
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "public, max-age=31536000")
h.ServeHTTP(w, r)
})
}