diff --git a/x/nocache.go b/x/nocache.go new file mode 100644 index 000000000000..324e80c8efed --- /dev/null +++ b/x/nocache.go @@ -0,0 +1,20 @@ +package x + +import ( + "net/http" + + "github.com/julienschmidt/httprouter" +) + +// NoCache adds `Cache-Control: 0` to the response header. +func NoCache(w http.ResponseWriter) { + w.Header().Set("Cache-Control", "0") +} + +// NoCacheHandler wraps httprouter.Handle with `Cache-Control: 0` headers. +func NoCacheHandler(handle httprouter.Handle) httprouter.Handle { + return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + NoCache(w) + handle(w, r, ps) + } +}