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 #3
master
alex 2 years ago
parent e7b2fad441
commit ae2e4afde7
Signed by: x1ddos
GPG Key ID: FDEFB4A63CBD8460

@ -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)
}

Loading…
Cancel
Save