Make sure cache is disabled for badges and charts

This commit is contained in:
TwiN 2021-11-24 18:36:31 -05:00
parent 1f8fd29dad
commit 0331c18401
2 changed files with 9 additions and 8 deletions

View File

@ -51,11 +51,10 @@ func UptimeBadge(writer http.ResponseWriter, request *http.Request) {
} }
return 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("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)) _, _ = writer.Write(generateUptimeBadgeSVG(duration, uptime))
} }
@ -89,11 +88,10 @@ func ResponseTimeBadge(writer http.ResponseWriter, request *http.Request) {
} }
return 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("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)) _, _ = writer.Write(generateResponseTimeBadgeSVG(duration, averageResponseTime))
} }

View File

@ -112,6 +112,9 @@ func ResponseTimeChart(writer http.ResponseWriter, r *http.Request) {
Series: []chart.Series{series}, Series: []chart.Series{series},
} }
writer.Header().Set("Content-Type", "image/svg+xml") 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 { if err := graph.Render(chart.SVG, writer); err != nil {
log.Println("[handler][ResponseTimeChart] Failed to render response time chart:", err.Error()) log.Println("[handler][ResponseTimeChart] Failed to render response time chart:", err.Error())
return return