From 69d130d04bfef56a0df2e89da77ee4b110f6bb9c Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Wed, 11 May 2022 16:33:35 +0100 Subject: [PATCH] Add Cache-Control headers to responses --- okserver.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/okserver.go b/okserver.go index ab68540..3de44c0 100644 --- a/okserver.go +++ b/okserver.go @@ -17,12 +17,18 @@ func main() { // Create a very simple HTTP server with two endpoints: one // that just replies "OK", and one that dumps the incoming // request back to the client. + // + // The OK handler answers with a cachable response, while the + // dynamic one sets cache-busting headers. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/echo": w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Expires", "-1") + w.Header().Set("Cache-Control", "no-store") r.Write(w) case "/", "/health": + w.Header().Set("Cache-Control", "max-age=86400") io.WriteString(w, "OK\n") default: http.NotFound(w, r) -- GitLab