Skip to content

Commit

Permalink
feat(dependencies): bump to Souin v1.6.39 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Jul 19, 2023
1 parent 1384484 commit 8a819c2
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 10 deletions.
52 changes: 52 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ route /custom-key/without-* {
respond "Hello to the authenticated user."
}

route /must-revalidate {
cache {
ttl 5s
stale 5s
}
header Cache-Control "must-revalidate"
reverse_proxy 127.0.0.1:81
}

route /cache-authorization {
cache {
cache_keys {
Expand All @@ -299,6 +308,49 @@ route /cache-authorization {
respond "Hello to the authenticated user."
}

route /bypass {
cache {
mode bypass
}

header Cache-Control "no-store"
respond "Hello bypass"
}

route /bypass_request {
cache {
mode bypass_request
}

respond "Hello bypass_request"
}

route /bypass_response {
cache {
mode bypass_response
}

header Cache-Control "no-cache, no-store"
respond "Hello bypass_response"
}

route /strict_request {
cache {
mode strict
}

respond "Hello strict"
}

route /strict_response {
cache {
mode strict
}

header Cache-Control "no-cache, no-store"
respond "Hello strict"
}

cache @souin-api {
}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Here are all the available options for the global options
headers Content-Type Authorization
}
log_level debug
mode bypass
nuts {
path /path/to/the/storage
}
Expand Down Expand Up @@ -384,6 +385,7 @@ What does these directives mean?
| `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)` |
| `mode` | Bypass the RFC respect | One of `bypass` `bypass_request` `bypass_response` `strict` (default `strict`) |
| `nuts` | Configure the Nuts cache storage | |
| `nuts.path` | Set the Nuts file path storage | `/anywhere/nuts/storage` |
| `nuts.configuration` | Configure Nuts directly in the Caddyfile or your JSON caddy configuration | [See the Nuts configuration for the options](https://github.com/nutsdb/nutsdb#default-options) |
Expand Down
45 changes: 42 additions & 3 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type DefaultCache struct {
Headers []string `json:"headers"`
// Configure the global key generation.
Key configurationtypes.Key `json:"key"`
// Mode defines if strict or bypass.
Mode string `json:"mode"`
// Olric provider configuration.
Olric configurationtypes.CacheProvider `json:"olric"`
// Redis provider configuration.
Expand Down Expand Up @@ -86,6 +88,11 @@ func (d *DefaultCache) GetEtcd() configurationtypes.CacheProvider {
return d.Etcd
}

// GetMode returns mdoe configuration
func (d *DefaultCache) GetMode() string {
return d.Mode
}

// GetNuts returns nuts configuration
func (d *DefaultCache) GetNuts() configurationtypes.CacheProvider {
return d.Nuts
Expand Down Expand Up @@ -274,6 +281,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
switch directive {
case "basepath":
apiConfiguration.Debug.BasePath = h.RemainingArgs()[0]
default:
return h.Errf("unsupported debug directive: %s", directive)
}
}
case "prometheus":
Expand All @@ -284,6 +293,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
switch directive {
case "basepath":
apiConfiguration.Prometheus.BasePath = h.RemainingArgs()[0]
default:
return h.Errf("unsupported prometheus directive: %s", directive)
}
}
case "souin":
Expand All @@ -294,8 +305,12 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
switch directive {
case "basepath":
apiConfiguration.Souin.BasePath = h.RemainingArgs()[0]
default:
return h.Errf("unsupported souin directive: %s", directive)
}
}
default:
return h.Errf("unsupported api directive: %s", directive)
}
}
cfg.API = apiConfiguration
Expand All @@ -310,6 +325,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
case "configuration":
provider.Configuration = parseCaddyfileRecursively(h)
provider.Configuration = parseBadgerConfiguration(provider.Configuration.(map[string]interface{}))
default:
return h.Errf("unsupported badger directive: %s", directive)
}
}
cfg.DefaultCache.Badger = provider
Expand Down Expand Up @@ -337,6 +354,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
ck.Hide = true
case "headers":
ck.Headers = h.RemainingArgs()
default:
return h.Errf("unsupported cache_keys (%s) directive: %s", rg, directive)
}
}

Expand Down Expand Up @@ -367,6 +386,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
cdn.Provider = h.RemainingArgs()[0]
case "strategy":
cdn.Strategy = h.RemainingArgs()[0]
default:
return h.Errf("unsupported cdn directive: %s", directive)
}
}
cfg.DefaultCache.CDN = cdn
Expand All @@ -381,6 +402,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
switch directive {
case "configuration":
provider.Configuration = parseCaddyfileRecursively(h)
default:
return h.Errf("unsupported etcd directive: %s", directive)
}
}
cfg.DefaultCache.Etcd = provider
Expand All @@ -403,12 +426,20 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
config_key.Hide = true
case "headers":
config_key.Headers = h.RemainingArgs()
default:
return h.Errf("unsupported key directive: %s", directive)
}
}
cfg.DefaultCache.Key = config_key
case "log_level":
args := h.RemainingArgs()
cfg.LogLevel = args[0]
case "mode":
args := h.RemainingArgs()
if len(args) > 1 {
return h.Errf("mode must contains only one arg: %s given", args)
}
cfg.DefaultCache.Mode = args[0]
case "nuts":
provider := configurationtypes.CacheProvider{}
for nesting := h.Nesting(); h.NextBlock(nesting); {
Expand All @@ -422,6 +453,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
provider.Path = urlArgs[0]
case "configuration":
provider.Configuration = parseCaddyfileRecursively(h)
default:
return h.Errf("unsupported nuts directive: %s", directive)
}
}
cfg.DefaultCache.Nuts = provider
Expand All @@ -439,6 +472,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
provider.Path = urlArgs[0]
case "configuration":
provider.Configuration = parseCaddyfileRecursively(h)
default:
return h.Errf("unsupported olric directive: %s", directive)
}
}
cfg.DefaultCache.Olric = provider
Expand All @@ -457,6 +492,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
case "configuration":
provider.Configuration = parseCaddyfileRecursively(h)
provider.Configuration = parseRedisConfiguration(provider.Configuration.(map[string]interface{}))
default:
return h.Errf("unsupported redis directive: %s", directive)
}
}
cfg.DefaultCache.Redis = provider
Expand All @@ -466,6 +503,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
switch directive {
case "exclude":
cfg.DefaultCache.Regex.Exclude = h.RemainingArgs()[0]
default:
return h.Errf("unsupported regex directive: %s", directive)
}
}
case "stale":
Expand Down Expand Up @@ -493,6 +532,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
d.Duration = ttl
}
timeout.Cache = d
default:
return h.Errf("unsupported timeout directive: %s", directive)
}
}
cfg.DefaultCache.Timeout = timeout
Expand All @@ -503,9 +544,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isBlocking b
cfg.DefaultCache.TTL.Duration = ttl
}
default:
if isBlocking {
return h.Errf("unsupported root directive: %s", rootOption)
}
return h.Errf("unsupported root directive: %s", rootOption)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/buraksezer/olric v0.5.4
github.com/caddyserver/caddy/v2 v2.6.4
github.com/darkweak/souin v1.6.36
github.com/darkweak/souin v1.6.39
go.uber.org/zap v1.24.0
)

Expand Down Expand Up @@ -102,7 +102,7 @@ require (
github.com/mschoch/smat v0.2.0 // indirect
github.com/onsi/ginkgo/v2 v2.9.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/pquerna/cachecontrol v0.1.1-0.20230415224848-baaf0ee61529 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.41.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/darkweak/go-esi v0.0.5 h1:b9LHI8Tz46R+i6p8avKPHAIBRQUCZDebNmKm5w/Zrns=
github.com/darkweak/go-esi v0.0.5/go.mod h1:koCJqwum1u6mslyZuq/Phm6hfG1K3ZK5Y7jrUBTH654=
github.com/darkweak/souin v1.6.36 h1:T+7xZFjnDgbjOPF/1jEFj3cBcTMK6hzdG0X3iQiGkGg=
github.com/darkweak/souin v1.6.36/go.mod h1:/C9ISWex+bkdmHgAT2wZpq9VQddcMLb0i8/ykrapN40=
github.com/darkweak/souin v1.6.39 h1:uVO18+pvy5N8dJH+CCfuBD3gx7AXWaBv+RjC9ee1pCk=
github.com/darkweak/souin v1.6.39/go.mod h1:7B7VqPbFrF7AWJDRP6FCbE+zGiRUUqHAmWOs3Q2n4hk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -1115,8 +1115,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc=
github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=
github.com/pquerna/cachecontrol v0.1.1-0.20230415224848-baaf0ee61529 h1:wcNVCAIsWcLpEJ5FhXHKC7dBi6SIZQukrOTY5eHes0M=
github.com/pquerna/cachecontrol v0.1.1-0.20230415224848-baaf0ee61529/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
Expand Down
Loading

0 comments on commit 8a819c2

Please sign in to comment.