Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Here are all the available options for the global options
disable_body
disable_host
disable_method
disable_query
headers X-Token Authorization
hide
}
Expand Down Expand Up @@ -115,6 +116,7 @@ Here are all the available options for the directive options
disable_body
disable_host
disable_method
disable_query
headers X-Token Authorization
}
}
Expand All @@ -133,6 +135,7 @@ Here are all the available options for the directive options
disable_body
disable_host
disable_method
disable_query
headers Content-Type Authorization
}
log_level debug
Expand Down Expand Up @@ -360,6 +363,7 @@ What does these directives mean?
| `cache_keys.{your regexp}.disable_body` | Disable the body part in the key matching the regexp (GraphQL context) | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.disable_host` | Disable the host part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.disable_method` | Disable the method part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.disable_query` | Disable the query string part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.headers` | Add headers to the key matching the regexp | `Authorization Content-Type X-Additional-Header` |
| `cache_keys.{your regexp}.hide` | Prevent the key from being exposed in the `Cache-Status` HTTP response header | `true`<br/><br/>`(default: false)` |
| `cdn` | The CDN management, if you use any cdn to proxy your requests Souin will handle that | |
Expand All @@ -377,6 +381,7 @@ What does these directives mean?
| `key.disable_body` | Disable the body part in the key (GraphQL context) | `true`<br/><br/>`(default: false)` |
| `key.disable_host` | Disable the host part in the key | `true`<br/><br/>`(default: false)` |
| `key.disable_method` | Disable the method part in the key | `true`<br/><br/>`(default: false)` |
| `key.disable_query` | Disable the query string part in the key | `true`<br/><br/>`(default: false)` |
| `key.headers` | Add headers to the key matching the regexp | `Authorization Content-Type X-Additional-Header` |
| `key.hide` | Prevent the key from being exposed in the `Cache-Status` HTTP response header | `true`<br/><br/>`(default: false)` |
| `nuts` | Configure the Nuts cache storage | |
Expand Down
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SouinApp struct {
// Surrogate storage to support th econfiguration reload without surrogate-key data loss.
SurrogateStorage providers.SurrogateInterface
// Cache-key tweaking.
CacheKeys map[string]configurationtypes.Key `json:"cache_keys,omitempty"`
CacheKeys configurationtypes.CacheKeys `json:"cache_keys,omitempty"`
// API endpoints enablers.
API configurationtypes.API `json:"api,omitempty"`
// Logger level, fallback on caddy's one when not redefined.
Expand Down
18 changes: 9 additions & 9 deletions configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpcache

import (
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -132,14 +133,13 @@ type Configuration struct {
// API endpoints enablers.
API configurationtypes.API
// Cache keys configuration.
CfgCacheKeys map[string]configurationtypes.Key
CacheKeys configurationtypes.CacheKeys `json:"cache_keys"`
// Override the ttl depending the cases.
URLs map[string]configurationtypes.URL
// Logger level, fallback on caddy's one when not redefined.
LogLevel string
// SurrogateKeys contains the surrogate keys to use with a predefined mapping
SurrogateKeys map[string]configurationtypes.SurrogateKeys
cacheKeys map[configurationtypes.RegValue]configurationtypes.Key
logger *zap.Logger
}

Expand Down Expand Up @@ -184,8 +184,8 @@ func (c *Configuration) GetSurrogateKeys() map[string]configurationtypes.Surroga
}

// GetCacheKeys get the cache keys rules to override
func (c *Configuration) GetCacheKeys() map[configurationtypes.RegValue]configurationtypes.Key {
return c.cacheKeys
func (c *Configuration) GetCacheKeys() configurationtypes.CacheKeys {
return c.CacheKeys
}

var _ configurationtypes.AbstractConfigurationInterface = (*Configuration)(nil)
Expand Down Expand Up @@ -314,9 +314,9 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
}
cfg.DefaultCache.Badger = provider
case "cache_keys":
cacheKeys := cfg.CfgCacheKeys
if cacheKeys == nil {
cacheKeys = make(map[string]configurationtypes.Key)
CacheKeys := cfg.CacheKeys
if CacheKeys == nil {
CacheKeys = make(configurationtypes.CacheKeys, 0)
}
for nesting := h.Nesting(); h.NextBlock(nesting); {
rg := h.Val()
Expand All @@ -340,9 +340,9 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
}
}

cacheKeys[rg] = ck
CacheKeys = append(CacheKeys, configurationtypes.CacheKey{configurationtypes.RegValue{Regexp: regexp.MustCompile(rg)}: ck})
}
cfg.CfgCacheKeys = cacheKeys
cfg.CacheKeys = CacheKeys
case "cache_name":
args := h.RemainingArgs()
cfg.DefaultCache.CacheName = args[0]
Expand Down
Loading