package middleware import ( "net/http" "time" "git.staur.ca/stobbsm/clustvirt/lib/log" ) // NoCache adds headers indicating the browser shouldn't cache // any of the responses. Useful for debugging, should not be used // on production func NoCache(next http.Handler) http.Handler { log.Info("router.middleware").Str("middleware", "NoCache").Msg("middleware loaded") return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Add("Cache-Control", "no-cache, no-store, no-transform, must-revalidate, private, max-age=0") w.Header().Add("Expires", time.Unix(0, 0).UTC().Format(http.TimeFormat)) w.Header().Add("Pragma", "no-cache") next.ServeHTTP(w, r) }) }