Set cache control headers in V2 API to mirror V1 (#3195)
* Set cache control headers Signed-off-by: Alex Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
parent
7923bc5f8e
commit
fe1b045c00
|
@ -130,11 +130,24 @@ func NewAPI(
|
|||
openAPI.SilencePostSilencesHandler = silence_ops.PostSilencesHandlerFunc(api.postSilencesHandler)
|
||||
|
||||
handleCORS := cors.Default().Handler
|
||||
api.Handler = handleCORS(openAPI.Serve(nil))
|
||||
api.Handler = handleCORS(setResponseHeaders(openAPI.Serve(nil)))
|
||||
|
||||
return &api, nil
|
||||
}
|
||||
|
||||
var responseHeaders = map[string]string{
|
||||
"Cache-Control": "no-store",
|
||||
}
|
||||
|
||||
func setResponseHeaders(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
for h, v := range responseHeaders {
|
||||
w.Header().Set(h, v)
|
||||
}
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (api *API) requestLogger(req *http.Request) log.Logger {
|
||||
return log.With(api.logger, "path", req.URL.Path, "method", req.Method)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue