Skip to content

Commit

Permalink
fix(plugins): handle stringified array from traefik configuration loa…
Browse files Browse the repository at this point in the history
…der (#333)
  • Loading branch information
darkweak authored Mar 31, 2023
1 parent 195397f commit d12869f
Show file tree
Hide file tree
Showing 29 changed files with 1,351 additions and 1,798 deletions.
1 change: 0 additions & 1 deletion plugins/traefik/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ prepare: vendor ## Prepare traefik plugin
# TODO find another way to do that
replace: ## Replace sources in the vendor folder deeper than the go mod replace
$(MAKE) copy-to base=$(CACHE) target=coalescing
$(MAKE) copy-to base=$(CACHE) target=providers
$(MAKE) copy-to base=$(SOUIN) target=context
$(MAKE) copy-file-to base=$(PKG) target=surrogate/providers/common.go
$(MAKE) copy-file-to base=$(CACHE) target=types/layerStorage.go
Expand Down
1 change: 0 additions & 1 deletion plugins/traefik/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.19
require (
github.com/akyoto/cache v1.0.6
github.com/darkweak/souin v1.6.36
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pquerna/cachecontrol v0.1.0
go.uber.org/zap v1.21.0
)
Expand Down
2 changes: 0 additions & 2 deletions plugins/traefik/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,6 @@ github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5h
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
Expand Down
14 changes: 14 additions & 0 deletions plugins/traefik/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,21 @@ func parseConfiguration(c map[string]interface{}) Configuration {
// parseStringSlice returns the string slice corresponding to the given interface.
// The interface can be of type string which contains a comma separated list of values (e.g. foo,bar) or of type []string.
func parseStringSlice(i interface{}) []string {
if value, ok := i.([]string); ok {
return value
}
if value, ok := i.([]interface{}); ok {
var arr []string
for _, v := range value {
arr = append(arr, v.(string))
}
return arr
}

if value, ok := i.(string); ok {
if strings.HasPrefix(value, "║24║") {
return strings.Split(strings.TrimPrefix(value, "║24║"), "║")
}
return strings.Split(value, ",")
}

Expand Down
4 changes: 0 additions & 4 deletions plugins/traefik/override/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ type handlerFunc = func(http.ResponseWriter, *http.Request) error

func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, next handlerFunc) error {
b, handler := s.HandleInternally(rq)
fmt.Println("AFTER")
fmt.Println("AFTER b", b)
if b {
handler(rw, rq)
return nil
Expand All @@ -193,13 +191,11 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
return next(rw, rq)
}

fmt.Println("RESPONSE 1")
if !rq.Context().Value(context.SupportedMethod).(bool) {
rw.Header().Set("Cache-Status", cacheName+"; fwd=uri-miss; detail=UNSUPPORTED-METHOD")

return next(rw, rq)
}
fmt.Println("RESPONSE 2")

requestCc, coErr := cacheobject.ParseRequestCacheControl(rq.Header.Get("Cache-Control"))

Expand Down
58 changes: 0 additions & 58 deletions plugins/traefik/override/providers/abstractProvider.go

This file was deleted.

17 changes: 0 additions & 17 deletions plugins/traefik/override/providers/abstractProvider_test.go

This file was deleted.

110 changes: 0 additions & 110 deletions plugins/traefik/override/providers/cacheProvider.go

This file was deleted.

1 change: 1 addition & 0 deletions plugins/traefik/override/storage/cacheProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (provider *Cache) Get(key string) []byte {
// Prefix method returns the populated response if exists, empty response then
func (provider *Cache) Prefix(key string, req *http.Request) []byte {
var result []byte

provider.Cache.Range(func(k, v interface{}) bool {
if k == key {
result = v.([]byte)
Expand Down
5 changes: 3 additions & 2 deletions plugins/traefik/override/ykeys/ykey.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package ykeys

import (
"fmt"
"github.com/patrickmn/go-cache"
"net/http"
"regexp"
"strings"
"time"

"github.com/akyoto/cache"

"github.com/darkweak/souin/configurationtypes"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func InitializeYKeys(keys map[string]configurationtypes.SurrogateKeys) *YKeyStor
return nil
}

c := cache.New(1*time.Second, 2*time.Second)
c := cache.New(1 * time.Second)

for key := range keys {
c.Set(key, "", 1)
Expand Down
1 change: 1 addition & 0 deletions plugins/traefik/souin-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ http:
regex:
exclude: '/excluded'
ttl: 5s
allowed_http_verbs: [GET, HEAD, POST]
default_cache_control: public
log_level: debug
urls:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading

0 comments on commit d12869f

Please sign in to comment.