add response headers to prevent caching
This commit is contained in:
parent
5ca7dadd02
commit
47f32e1468
@ -172,6 +172,12 @@ func main() {
|
|||||||
|
|
||||||
apiHandler := logMiddleware(logger.WithNamespace("api"), apiMux)
|
apiHandler := logMiddleware(logger.WithNamespace("api"), apiMux)
|
||||||
apiHandler = annotateMiddleware(apiHandler)
|
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))
|
mux.Handle("/api/", http.StripPrefix("/api", apiHandler))
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
@ -9,6 +9,15 @@ import (
|
|||||||
"github.com/mediocregopher/mediocre-go-lib/v2/mlog"
|
"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 {
|
func annotateMiddleware(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user