From 54dcc4da2ff22bdb17e53dd6eac1c0bd54a20390 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Mon, 27 Jul 2020 12:09:25 +0200 Subject: [PATCH] feat: add nocache helpers --- x/nocache.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 x/nocache.go diff --git a/x/nocache.go b/x/nocache.go new file mode 100644 index 00000000000..324e80c8efe --- /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) + } +}