Matthew Stobbs
4c132c4abf
- switched to go 1.22 net/http ServeMux for routing - seems to be working really well
23 lines
696 B
Go
23 lines
696 B
Go
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)
|
|
})
|
|
}
|