Skip to content

Commit b75cf1a

Browse files
committed
add no-caching headers
1 parent bd83843 commit b75cf1a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmd/alertmanager/restapi.go

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func newRestApi(ctx context.Context) http.Handler {
3030
mux := httputils.NewMethodMux()
3131

3232
mux.GET.HandleFunc("/alerts", func(w http.ResponseWriter, r *http.Request) {
33+
noCacheHeaders(w)
34+
3335
handleJsonOutput(w, app.State.ActiveAlerts())
3436
})
3537

@@ -57,6 +59,8 @@ func newRestApi(ctx context.Context) http.Handler {
5759
mux.GET.HandleFunc("/alerts/acknowledge", func(w http.ResponseWriter, r *http.Request) {
5860
id := r.URL.Query().Get("id")
5961

62+
noCacheHeaders(w)
63+
6064
if err := alertAck(r.Context(), id); err != nil {
6165
http.Error(w, err.Error(), http.StatusInternalServerError)
6266
return
@@ -66,13 +70,17 @@ func newRestApi(ctx context.Context) http.Handler {
6670
})
6771

6872
mux.GET.HandleFunc("/deadmansswitches", func(w http.ResponseWriter, r *http.Request) {
73+
noCacheHeaders(w)
74+
6975
handleJsonOutput(w, app.State.DeadMansSwitches())
7076
})
7177

7278
// /deadmansswitch/checkin?subject=ubackup_done&ttl=24h30m
7379
mux.GET.HandleFunc("/deadmansswitch/checkin", func(w http.ResponseWriter, r *http.Request) {
7480
// same semantic hack here as acknowledge endpoint
7581

82+
noCacheHeaders(w)
83+
7684
// handles validation
7785
handleDeadMansSwitchCheckin(w, r, alertmanagertypes.DeadMansSwitchCheckinRequest{
7886
Subject: r.URL.Query().Get("subject"),
@@ -173,3 +181,7 @@ func runStandaloneRestApi(ctx context.Context, logger *log.Logger) error {
173181
func ackLink(alert amstate.Alert) string {
174182
return os.Getenv("API_ENDPOINT") + "/alerts/acknowledge?id=" + alert.Id
175183
}
184+
185+
func noCacheHeaders(w http.ResponseWriter) {
186+
w.Header().Set("Cache-Control", "no-store, must-revalidate")
187+
}

0 commit comments

Comments
 (0)