Skip to content

Instantly share code, notes, and snippets.

@a-h
Created August 20, 2019 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-h/c0d85863621a67e980f7fad44e645fbc to your computer and use it in GitHub Desktop.
Save a-h/c0d85863621a67e980f7fad44e645fbc to your computer and use it in GitHub Desktop.
Disable caching and sniffing via HTTP headers
func DisableCachingAndSniffing(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate;")
w.Header().Set("pragma", "no-cache")
w.Header().Set("X-Content-Type-Options", "nosniff")
next.ServeHTTP(w, r)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment