From 0331c18401a11eed0fd1931fc2b370ea048bdbe1 Mon Sep 17 00:00:00 2001 From: TwiN Date: Wed, 24 Nov 2021 18:36:31 -0500 Subject: [PATCH] Make sure cache is disabled for badges and charts --- controller/handler/badge.go | 14 ++++++-------- controller/handler/chart.go | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/controller/handler/badge.go b/controller/handler/badge.go index 99e1cc24..a7e3af1d 100644 --- a/controller/handler/badge.go +++ b/controller/handler/badge.go @@ -51,11 +51,10 @@ func UptimeBadge(writer http.ResponseWriter, request *http.Request) { } return } - formattedDate := time.Now().Format(http.TimeFormat) - writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - writer.Header().Set("Date", formattedDate) - writer.Header().Set("Expires", formattedDate) writer.Header().Set("Content-Type", "image/svg+xml") + writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + writer.Header().Set("Expires", "0") + writer.WriteHeader(http.StatusOK) _, _ = writer.Write(generateUptimeBadgeSVG(duration, uptime)) } @@ -89,11 +88,10 @@ func ResponseTimeBadge(writer http.ResponseWriter, request *http.Request) { } return } - formattedDate := time.Now().Format(http.TimeFormat) - writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - writer.Header().Set("Date", formattedDate) - writer.Header().Set("Expires", formattedDate) writer.Header().Set("Content-Type", "image/svg+xml") + writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + writer.Header().Set("Expires", "0") + writer.WriteHeader(http.StatusOK) _, _ = writer.Write(generateResponseTimeBadgeSVG(duration, averageResponseTime)) } diff --git a/controller/handler/chart.go b/controller/handler/chart.go index b8213b9c..d2df7809 100644 --- a/controller/handler/chart.go +++ b/controller/handler/chart.go @@ -112,6 +112,9 @@ func ResponseTimeChart(writer http.ResponseWriter, r *http.Request) { Series: []chart.Series{series}, } writer.Header().Set("Content-Type", "image/svg+xml") + writer.Header().Set("Cache-Control", "no-cache, no-store") + writer.Header().Set("Expires", "0") + writer.WriteHeader(http.StatusOK) if err := graph.Render(chart.SVG, writer); err != nil { log.Println("[handler][ResponseTimeChart] Failed to render response time chart:", err.Error()) return