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:
Alexander Weaver 2023-02-07 09:57:54 -06:00 committed by GitHub
parent 7923bc5f8e
commit fe1b045c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -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)
}