Skip to content

Commit 787c94b

Browse files
update README and default configuration file, bump Souin to latest (#49)
* update README and default configuration file * feat: bump to latest Souin (1.6.36), bring some changes from the souin repo * Update httpcache.go Co-authored-by: darkweak <darkweak@protonmail.com> * Update httpcache.go Co-authored-by: darkweak <darkweak@protonmail.com> * Update httpcache.go Co-authored-by: darkweak <darkweak@protonmail.com> * Update httpcache.go Co-authored-by: darkweak <darkweak@protonmail.com> * fix --------- Co-authored-by: darkweak <darkweak@protonmail.com>
1 parent 5ba50ef commit 787c94b

File tree

8 files changed

+198
-24
lines changed

8 files changed

+198
-24
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Here are all the available options for the global options
5050
disable_body
5151
disable_host
5252
disable_method
53+
disable_query
5354
headers X-Token Authorization
5455
hide
5556
}
@@ -115,6 +116,7 @@ Here are all the available options for the directive options
115116
disable_body
116117
disable_host
117118
disable_method
119+
disable_query
118120
headers X-Token Authorization
119121
}
120122
}
@@ -133,6 +135,7 @@ Here are all the available options for the directive options
133135
disable_body
134136
disable_host
135137
disable_method
138+
disable_query
136139
headers Content-Type Authorization
137140
}
138141
log_level debug
@@ -360,6 +363,7 @@ What does these directives mean?
360363
| `cache_keys.{your regexp}.disable_body` | Disable the body part in the key matching the regexp (GraphQL context) | `true`<br/><br/>`(default: false)` |
361364
| `cache_keys.{your regexp}.disable_host` | Disable the host part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
362365
| `cache_keys.{your regexp}.disable_method` | Disable the method part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
366+
| `cache_keys.{your regexp}.disable_query` | Disable the query string part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
363367
| `cache_keys.{your regexp}.headers` | Add headers to the key matching the regexp | `Authorization Content-Type X-Additional-Header` |
364368
| `cache_keys.{your regexp}.hide` | Prevent the key from being exposed in the `Cache-Status` HTTP response header | `true`<br/><br/>`(default: false)` |
365369
| `cdn` | The CDN management, if you use any cdn to proxy your requests Souin will handle that | |
@@ -377,6 +381,7 @@ What does these directives mean?
377381
| `key.disable_body` | Disable the body part in the key (GraphQL context) | `true`<br/><br/>`(default: false)` |
378382
| `key.disable_host` | Disable the host part in the key | `true`<br/><br/>`(default: false)` |
379383
| `key.disable_method` | Disable the method part in the key | `true`<br/><br/>`(default: false)` |
384+
| `key.disable_query` | Disable the query string part in the key | `true`<br/><br/>`(default: false)` |
380385
| `key.headers` | Add headers to the key matching the regexp | `Authorization Content-Type X-Additional-Header` |
381386
| `key.hide` | Prevent the key from being exposed in the `Cache-Status` HTTP response header | `true`<br/><br/>`(default: false)` |
382387
| `nuts` | Configure the Nuts cache storage | |

app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type SouinApp struct {
1717
// Surrogate storage to support th econfiguration reload without surrogate-key data loss.
1818
SurrogateStorage providers.SurrogateInterface
1919
// Cache-key tweaking.
20-
CacheKeys map[string]configurationtypes.Key `json:"cache_keys,omitempty"`
20+
CacheKeys configurationtypes.CacheKeys `json:"cache_keys,omitempty"`
2121
// API endpoints enablers.
2222
API configurationtypes.API `json:"api,omitempty"`
2323
// Logger level, fallback on caddy's one when not redefined.

configuration.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package httpcache
22

33
import (
4+
"regexp"
45
"strconv"
56
"strings"
67
"time"
@@ -132,14 +133,13 @@ type Configuration struct {
132133
// API endpoints enablers.
133134
API configurationtypes.API
134135
// Cache keys configuration.
135-
CfgCacheKeys map[string]configurationtypes.Key
136+
CacheKeys configurationtypes.CacheKeys `json:"cache_keys"`
136137
// Override the ttl depending the cases.
137138
URLs map[string]configurationtypes.URL
138139
// Logger level, fallback on caddy's one when not redefined.
139140
LogLevel string
140141
// SurrogateKeys contains the surrogate keys to use with a predefined mapping
141142
SurrogateKeys map[string]configurationtypes.SurrogateKeys
142-
cacheKeys map[configurationtypes.RegValue]configurationtypes.Key
143143
logger *zap.Logger
144144
}
145145

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

186186
// GetCacheKeys get the cache keys rules to override
187-
func (c *Configuration) GetCacheKeys() map[configurationtypes.RegValue]configurationtypes.Key {
188-
return c.cacheKeys
187+
func (c *Configuration) GetCacheKeys() configurationtypes.CacheKeys {
188+
return c.CacheKeys
189189
}
190190

191191
var _ configurationtypes.AbstractConfigurationInterface = (*Configuration)(nil)
@@ -314,9 +314,9 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
314314
}
315315
cfg.DefaultCache.Badger = provider
316316
case "cache_keys":
317-
cacheKeys := cfg.CfgCacheKeys
318-
if cacheKeys == nil {
319-
cacheKeys = make(map[string]configurationtypes.Key)
317+
CacheKeys := cfg.CacheKeys
318+
if CacheKeys == nil {
319+
CacheKeys = make(configurationtypes.CacheKeys, 0)
320320
}
321321
for nesting := h.Nesting(); h.NextBlock(nesting); {
322322
rg := h.Val()
@@ -340,9 +340,9 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
340340
}
341341
}
342342

343-
cacheKeys[rg] = ck
343+
CacheKeys = append(CacheKeys, configurationtypes.CacheKey{configurationtypes.RegValue{Regexp: regexp.MustCompile(rg)}: ck})
344344
}
345-
cfg.CfgCacheKeys = cacheKeys
345+
cfg.CacheKeys = CacheKeys
346346
case "cache_name":
347347
args := h.RemainingArgs()
348348
cfg.DefaultCache.CacheName = args[0]

0 commit comments

Comments
 (0)