From 13aae9a72cc1168e10a8e496286167b990781106 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Thu, 12 Dec 2024 14:31:58 +0100 Subject: [PATCH 1/2] Add cache headers to POSIX version too. --- cmd/conformance/posix/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/conformance/posix/main.go b/cmd/conformance/posix/main.go index cc1fcf3b..5b166f16 100644 --- a/cmd/conformance/posix/main.go +++ b/cmd/conformance/posix/main.go @@ -49,6 +49,13 @@ func init() { }) } +func addCacheHeaders(value string, fs http.Handler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Cache-Control", value) + fs.ServeHTTP(w, r) + } +} + func main() { klog.InitFlags(nil) flag.Parse() @@ -84,7 +91,10 @@ func main() { }) // Proxy all GET requests to the filesystem as a lightweight file server. // This makes it easier to test this implementation from another machine. - http.Handle("GET /", http.FileServer(http.Dir(*storageDir))) + fs := http.FileServer(http.Dir(*storageDir)) + http.Handle("GET /checkpoint", addCacheHeaders("no-cache", fs)) + http.Handle("GET /tile/", addCacheHeaders("public, max-age=31536000, immutable", fs)) + http.Handle("GET /", fs) // TODO(mhutchinson): Change the listen flag to just a port, or fix up this address formatting klog.Infof("Environment variables useful for accessing this log:\n"+ From d09c7fdb710339b940ac66162dd6bdfce1949569 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Thu, 12 Dec 2024 16:34:05 +0100 Subject: [PATCH 2/2] Remove `public` as suggested. --- cmd/conformance/posix/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/conformance/posix/main.go b/cmd/conformance/posix/main.go index 5b166f16..5d1c4ef1 100644 --- a/cmd/conformance/posix/main.go +++ b/cmd/conformance/posix/main.go @@ -93,7 +93,7 @@ func main() { // This makes it easier to test this implementation from another machine. fs := http.FileServer(http.Dir(*storageDir)) http.Handle("GET /checkpoint", addCacheHeaders("no-cache", fs)) - http.Handle("GET /tile/", addCacheHeaders("public, max-age=31536000, immutable", fs)) + http.Handle("GET /tile/", addCacheHeaders("max-age=31536000, immutable", fs)) http.Handle("GET /", fs) // TODO(mhutchinson): Change the listen flag to just a port, or fix up this address formatting