From 8dd8ebacc1da22f1c330f1a4cadbc07aa6f253e4 Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Fri, 28 Aug 2026 11:16:15 +0100 Subject: [PATCH] cmd/packserver: better default behaviour for --expiry404 Now inherits from --expiry, but with a maximum of 60s. Intended to allow for short negative caching, without causing issues with newly-created assets. --- cmd/packserver/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/packserver/main.go b/cmd/packserver/main.go index 86c813b..c51ba00 100644 --- a/cmd/packserver/main.go +++ b/cmd/packserver/main.go @@ -56,7 +56,7 @@ func main() { rootCmd.Flags().Duration("expiry", 0, "Tell client how long it can cache data for; 0 means no caching") rootCmd.Flags().Duration("expiry404", 0, - "Tell client how long it can cache 404 responses for; 0 means no caching") + "Tell client how long it can cache 404 responses for; 0 means default (inherit from --expiry, max. 60s); -1 means no caching") rootCmd.Flags().String("fallback-404", "", "Name of file to return if response would be 404 (spa.html or similar)") rootCmd.Flags().String("frames", "sameorigin", @@ -145,12 +145,18 @@ func run(c *cobra.Command, args []string) error { if expiry > 0 { cacheControl200 = fmt.Sprintf("public, max-age=%d", expiry/1e9) } - expiry, err = c.Flags().GetDuration("expiry404") + + expiry404, err := c.Flags().GetDuration("expiry404") if err != nil { return err } - if expiry > 0 { - cacheControl404 = fmt.Sprintf("public, max-age=%d", expiry/1e9) + switch { + case expiry404 == 0 && expiry == 0: + case expiry404 == 0 && expiry > 0: + expiry404 = min(60*time.Second, expiry) + fallthrough + case expiry404 > 0: + cacheControl404 = fmt.Sprintf("public, max-age=%d", expiry404/1e9) } // optional index file