nocache.go 540 B

1234567891011121314151617181920212223242526
  1. package util
  2. import (
  3. "net/http"
  4. "time"
  5. )
  6. var epoch = time.Unix(0, 0).Format(time.RFC1123)
  7. var noCacheHeaders = map[string]string{
  8. "Expires": epoch,
  9. "Cache-Control": "no-cache, private, max-age=0",
  10. "Pragma": "no-cache",
  11. "X-Accel-Expires": "0",
  12. }
  13. // NoCache writes nocache headers
  14. func NoCache(h http.Handler) http.HandlerFunc {
  15. fn := func(w http.ResponseWriter, r *http.Request) {
  16. // Set our NoCache headers
  17. for k, v := range noCacheHeaders {
  18. w.Header().Set(k, v)
  19. }
  20. h.ServeHTTP(w, r)
  21. }
  22. return fn
  23. }