Skip to content
Snippets Groups Projects
Commit 69d130d0 authored by ale's avatar ale
Browse files

Add Cache-Control headers to responses

parent f686fff3
No related branches found
No related tags found
No related merge requests found
Pipeline #32220 passed
...@@ -17,12 +17,18 @@ func main() { ...@@ -17,12 +17,18 @@ func main() {
// Create a very simple HTTP server with two endpoints: one // Create a very simple HTTP server with two endpoints: one
// that just replies "OK", and one that dumps the incoming // that just replies "OK", and one that dumps the incoming
// request back to the client. // 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) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path { switch r.URL.Path {
case "/echo": case "/echo":
w.Header().Set("Content-Type", "text/plain") w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Expires", "-1")
w.Header().Set("Cache-Control", "no-store")
r.Write(w) r.Write(w)
case "/", "/health": case "/", "/health":
w.Header().Set("Cache-Control", "max-age=86400")
io.WriteString(w, "OK\n") io.WriteString(w, "OK\n")
default: default:
http.NotFound(w, r) http.NotFound(w, r)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment