-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Description
The cache_keys configuration directive in the Caddy plugin does not work. The regex patterns defined in cache_keys are not applied, and the cache key is generated with default settings regardless of the configuration.
Environment
Souin version: latest (main branch)
Using this file.
handle @invalidPath {
rewrite * /{lang}/404
}
cache {
ttl 30s
stale 30s
default_cache_control public, s-maxage=30,stale-while-revalidate=30
# key {
# disable_query
# }
cache_keys {
.+\/404$ {
disable_host
}
}
}
I always get cache key as domain.com/-en/404 instead of en/404.
Some analysis
The bug seems to be coming from parseJSON, but I can't confirm
func (c *CacheKeys) parseJSON(rootDecoder *json.Decoder) {
_, _ = rootDecoder.Token() // skips token 1
_, _ = rootDecoder.Token() // skips token 2
_, _ = rootDecoder.Token() // skips token 3
For {".":{"disable_host":true}} Regex pattern becomes disable_host instead of .
After adding some debug logs
[DEBUG] cache_keys parsing: regex pattern = .*
[DEBUG] CacheKeys.MarshalJSON: {".": {"disable_host":true}}
[DEBUG] CacheKeys.UnmarshalJSON: {".":{"disable_host":true}}
[DEBUG] GetCacheKeys: [map[disable_host:{DisableHost:false}]]
hasOverride := false
for _, current := range g.overrides {
for k, v := range current {
fmt.Printf("[DEBUG] computeKey: testing regex=%s against URI=%s\n", k.String(), req.RequestURI)
if k.MatchString(req.RequestURI) {
[DEBUG] computeKey: testing regex=disable_host against URI=/de