From ae2e4afde78876d84402ae6af9ddceaf064e379a Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 10 Dec 2022 19:05:40 +0100 Subject: [PATCH] cmd/noxy: add a minimal unconditional cache-control header so the browsers will hopefully cache responses for 1h and reduce load on the server. a future version will propagate cache-control from upstream. part of https://git.qcode.ch/nostr/noxy/issues/3 --- cmd/noxy/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/noxy/main.go b/cmd/noxy/main.go index c014149..b60d67a 100644 --- a/cmd/noxy/main.go +++ b/cmd/noxy/main.go @@ -24,6 +24,7 @@ var ( listenAddr = flag.String("addr", "127.0.0.1:8889", "listen address") cacheDir = flag.String("cachedir", "/tmp", "absolute cache dir") maxFileSize = flag.Int64("maxfilesize", 1<<23, "refuse to handle files larger than this, in bytes") + minCacheAge = flag.Uint("mincacheage", 3600, "min cache-control max-age value, in seconds") idleRelayTimeout = flag.Duration("idlerelaytimeout", 10*time.Minute, "remove relay connections after idling this long") showVersion = flag.Bool("V", false, "print version and exit") @@ -164,6 +165,7 @@ func handleMeta(w http.ResponseWriter, r *http.Request) { Images: meta.ImageURLs, } w.Header().Set("Content-Type", "application/json") + w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", *minCacheAge)) json.NewEncoder(w).Encode(res) } @@ -183,6 +185,7 @@ func handleData(w http.ResponseWriter, r *http.Request) { } defer ds.Close() w.Header().Set("Content-Type", ds.ContentType) + w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", *minCacheAge)) io.Copy(w, ds) }