From fe1b045c00204dc47a0f63728b6162e9d5cf9b5e Mon Sep 17 00:00:00 2001 From: Alexander Weaver Date: Tue, 7 Feb 2023 09:57:54 -0600 Subject: [PATCH] Set cache control headers in V2 API to mirror V1 (#3195) * Set cache control headers Signed-off-by: Alex Weaver --- api/v2/api.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/v2/api.go b/api/v2/api.go index b272322c..4a723f57 100644 --- a/api/v2/api.go +++ b/api/v2/api.go @@ -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) }