add response headers to prevent caching

This commit is contained in:
Brian Picciano 2021-08-04 17:12:16 -06:00
parent 5ca7dadd02
commit 47f32e1468
2 changed files with 15 additions and 0 deletions

View File

@ -172,6 +172,12 @@ func main() {
apiHandler := logMiddleware(logger.WithNamespace("api"), apiMux)
apiHandler = annotateMiddleware(apiHandler)
apiHandler = addResponseHeaders(map[string]string{
"Cache-Control": "no-store, max-age=0",
"Pragma": "no-cache",
"Expires": "0",
}, apiHandler)
mux.Handle("/api/", http.StripPrefix("/api", apiHandler))
// run

View File

@ -9,6 +9,15 @@ import (
"github.com/mediocregopher/mediocre-go-lib/v2/mlog"
)
func addResponseHeaders(headers map[string]string, h http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
for k, v := range headers {
rw.Header().Set(k, v)
}
h.ServeHTTP(rw, r)
})
}
func annotateMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {