From 66f2ce8764bddefadc33a62d0f8533fce0bac804 Mon Sep 17 00:00:00 2001 From: jtelo88 Date: Wed, 5 Aug 2026 11:24:29 -0400 Subject: [PATCH] fix: FromApp inherits the app-level api {} config into site handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The api {} block is global-only in the Caddyfile adapter, but FromApp never copied app.API into the handler configuration, so GenerateHandlerMap built a nil handler map in every http.handlers.cache instance: the souin API was unreachable in-band on any listener — a PURGE/GET to /souin-api/* fell through the cache handler as an ordinary request. Inherit the app-level API (only when the handler config carries none of its own, which raw-JSON configs still can) exactly like the other app-level defaults merged here. --- httpcache.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/httpcache.go b/httpcache.go index 0cdcd87..b051d40 100644 --- a/httpcache.go +++ b/httpcache.go @@ -136,6 +136,17 @@ func (s *SouinCaddyMiddleware) FromApp(app *SouinApp) error { } } + // The Caddyfile `api {}` block is global-only (parseCaddyfileGlobalOption + // rejects it inside site blocks), so a handler's own configuration can + // only carry an API config via raw JSON. When it doesn't, inherit the + // app-level API like every other app-level default merged below — + // otherwise GenerateHandlerMap sees a zero API config in every handler + // instance and the souin API is unreachable in-band on any listener + // (requests fall through the cache handler as if the API didn't exist). + if !s.Configuration.API.Souin.Enable && !s.Configuration.API.Debug.Enable && !s.Configuration.API.Prometheus.Enable { + s.Configuration.API = app.API + } + if app.GetTTL() == 0 { if s.Configuration.DefaultCache.GetTTL() == 0 { app.TTL = configurationtypes.Duration{Duration: 120 * time.Second}