diff --git a/cache/surrogate/providers/common.go b/cache/surrogate/providers/common.go index 04e59f767..498a50707 100644 --- a/cache/surrogate/providers/common.go +++ b/cache/surrogate/providers/common.go @@ -44,6 +44,9 @@ func uniqueTag(values []string) []string { list := []string{} for _, item := range values { + if item == "" { + continue + } if _, found := tmp[item]; !found { tmp[item] = true list = append(list, item) @@ -103,6 +106,7 @@ func (s *baseStorage) storeTag(tag string, cacheKey string, re *regexp.Regexp) { if currentValue, b := s.Storage[tag]; s.dynamic || b { if !re.MatchString(currentValue) { s.Storage[tag] = currentValue + souinStorageSeparator + cacheKey + s.Storage[stalePrefix+tag] = currentValue + souinStorageSeparator + stalePrefix + cacheKey } } } diff --git a/docs/e2e/Souin E2E.postman_collection.json b/docs/e2e/Souin E2E.postman_collection.json index b9be56ad9..01b1070f1 100644 --- a/docs/e2e/Souin E2E.postman_collection.json +++ b/docs/e2e/Souin E2E.postman_collection.json @@ -2,9 +2,165 @@ "info": { "_postman_id": "9f52cee6-d2bb-4c17-8169-1bd7126975f4", "name": "Souin E2E", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "17806531" }, "item": [ + { + "name": "Beego", + "item": [ + { + "name": "Default", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/default`, '', true)" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Cache-Control", + "value": "", + "type": "text" + } + ], + "url": { + "raw": "{{app_url}}/default", + "host": [ + "{{app_url}}" + ], + "path": [ + "default" + ] + } + }, + "response": [] + }, + { + "name": "Default no cache", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/default`, 'no-cache')" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{app_url}}/default", + "host": [ + "{{app_url}}" + ], + "path": [ + "default" + ] + } + }, + "response": [] + }, + { + "name": "Default no store", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/default`, 'no-store')" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Cache-Control", + "value": "no-store", + "type": "text" + } + ], + "url": { + "raw": "{{app_url}}/default", + "host": [ + "{{app_url}}" + ], + "path": [ + "default" + ] + } + }, + "response": [] + }, + { + "name": "Exclude regex", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/test2`, '', false, true)" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Cache-Control", + "value": "", + "type": "text" + } + ], + "url": { + "raw": "{{app_url}}/excluded", + "host": [ + "{{app_url}}" + ], + "path": [ + "excluded" + ] + } + }, + "response": [] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "pm.collectionVariables.set('app_url', pm.collectionVariables.get('beego_url'))" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] + }, { "name": "Caddy", "item": [ @@ -447,7 +603,7 @@ " 'Surrogate-Key': key,", " },", " method,", - " url: `${utils.getVar(pm, 'app_url')}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}/surrogate_keys`,", + " url: `${utils.getVar(pm, 'app_url')}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}${method != 'PURGE' ? '/surrogate_keys' : ''}`,", "})", "const KEYS = {", " PREFIX: {", @@ -2620,6 +2776,11 @@ { "key": "app_url", "value": "" + }, + { + "key": "beego_url", + "value": "http://domain.com", + "type": "string" } ] } \ No newline at end of file diff --git a/plugins/caddy/Caddyfile b/plugins/caddy/Caddyfile index ab1ba4c4f..7db2414cb 100644 --- a/plugins/caddy/Caddyfile +++ b/plugins/caddy/Caddyfile @@ -12,6 +12,7 @@ } cdn { dynamic + strategy hard } regex { exclude /test2.* @@ -77,9 +78,7 @@ route /no-reverse-proxy { } route /surrogate-keys { - cache { - ttl 1m - } + cache header Surrogate-Key "KEY-{http.request.header.X-Surrogate-Key-Suffix}" header Vary X-Surrogate-Key-Suffix respond "Hello {http.request.header.X-Surrogate-Key-Suffix}"