From 3683f95933653b04d9f4f900cccfb5adc59eb9ac Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Sat, 29 Mar 2025 21:15:50 -0400 Subject: Add middleware to set Cache-Control header for challenge HTML (#132) * Add middleware to set Cache-Control header for challenge HTML * Add `NoStoreCache` middleware function in `internal/headers.go` to set Cache-Control: no-store header * Apply `NoStoreCache` middleware in `cmd/anubis/main.go` to set Cache-Control header for challenge HTML * docs: Add no-cache header information for challenge page * docs: Update changelog to reflect no-store Cache-Control header addition for challenge page * refactor: rename variable for clarity and update caching middleware in RenderIndex * chore: move changes to the unreleased section Signed-off-by: Jason Cameron --------- Signed-off-by: Jason Cameron Signed-off-by: Jason Cameron --- internal/headers.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'internal') diff --git a/internal/headers.go b/internal/headers.go index a48ce54..5c6a218 100644 --- a/internal/headers.go +++ b/internal/headers.go @@ -64,6 +64,15 @@ func XForwardedForToXRealIP(next http.Handler) http.Handler { }) } +// NoStoreCache sets the Cache-Control header to no-store for the response. +func NoStoreCache(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "no-store") + next.ServeHTTP(w, r) + }) +} + + // Do not allow browsing directory listings in paths that end with / func NoBrowsing(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3