Skip to content

Commit

Permalink
feat: add nocache helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jul 27, 2020
1 parent 7a2946e commit 54dcc4d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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)
}
}

0 comments on commit 54dcc4d

Please sign in to comment.