Skip to content

Commit

Permalink
fix(chore): traefik consummed request body (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Mar 13, 2023
1 parent 8d6d13f commit 2e3394c
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ experimental:
plugins:
souin:
moduleName: github.com/darkweak/souin
version: v1.6.34
version: v1.6.35
```
After that you can declare either the whole configuration at once in the middleware block or by service. See the examples below.
```yaml
Expand Down
4 changes: 2 additions & 2 deletions plugins/beego/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/beego/beego/v2 v2.0.7
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
)

require (
Expand Down Expand Up @@ -86,4 +86,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/caddy/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.34
github.com/darkweak/souin v1.6.35
go.uber.org/zap v1.24.0
)

Expand Down Expand Up @@ -178,4 +178,4 @@ require (
howett.net/plist v1.0.0 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/chi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/chi
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/go-chi/chi/v5 v5.0.8
)

Expand Down Expand Up @@ -83,4 +83,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/dotweb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/dotweb
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/devfeel/dotweb v1.7.19
)

Expand Down Expand Up @@ -84,4 +84,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/echo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/echo
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/labstack/echo/v4 v4.10.2
)

Expand Down Expand Up @@ -89,4 +89,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
3 changes: 3 additions & 0 deletions plugins/echo/souin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var (
Regex: configurationtypes.Regex{
Exclude: "/excluded",
},
Nuts: configurationtypes.CacheProvider{
Path: "./tmp",
},
TTL: configurationtypes.Duration{
Duration: 5 * time.Second,
},
Expand Down
4 changes: 2 additions & 2 deletions plugins/fiber/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/fiber
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/gofiber/fiber/v2 v2.42.0
github.com/valyala/fasthttp v1.44.0
)
Expand Down Expand Up @@ -95,4 +95,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/gin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/gin
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/gin-gonic/gin v1.9.0
)

Expand Down Expand Up @@ -101,4 +101,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/go-zero/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/go-zero
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/zeromicro/go-zero v1.5.0
)

Expand Down Expand Up @@ -107,4 +107,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/goyave/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/goyave
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
goyave.dev/goyave/v4 v4.4.8
)

Expand Down Expand Up @@ -90,4 +90,4 @@ require (
gorm.io/gorm v1.24.6 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/kratos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/kratos
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/go-kratos/kratos/v2 v2.5.4
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -86,4 +86,4 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/roadrunner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/roadrunner
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/roadrunner-server/errors v1.2.0
go.uber.org/zap v1.24.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -83,4 +83,4 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/skipper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/skipper
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/zalando/skipper v0.13.225
)

Expand Down Expand Up @@ -127,4 +127,4 @@ require (
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/traefik/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/traefik
go 1.19

require (
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
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 Expand Up @@ -85,4 +85,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
13 changes: 7 additions & 6 deletions plugins/traefik/override/context/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ func isMutation(b []byte) bool {
}

func (g *graphQLContext) SetContext(req *http.Request) *http.Request {
rq := req.WithContext(context.WithValue(req.Context(), GraphQL, g.custom))
rq = rq.WithContext(context.WithValue(rq.Context(), HashBody, ""))
rq = rq.WithContext(context.WithValue(rq.Context(), IsMutationRequest, false))
ctx := req.Context()
ctx = context.WithValue(ctx, GraphQL, g.custom)
ctx = context.WithValue(ctx, HashBody, "")
ctx = context.WithValue(ctx, IsMutationRequest, false)

if g.custom && req.Body != nil {
b := bytes.NewBuffer([]byte{})
_, _ = io.Copy(b, req.Body)
req.Body = io.NopCloser(b)
if b.Len() > 0 {
if isMutation(b.Bytes()) {
rq = rq.WithContext(context.WithValue(rq.Context(), IsMutationRequest, true))
ctx = context.WithValue(ctx, IsMutationRequest, true)
} else {
h := sha256.New()
h.Write(b.Bytes())
rq = rq.WithContext(context.WithValue(rq.Context(), HashBody, fmt.Sprintf("-%x", h.Sum(nil))))
ctx = context.WithValue(ctx, HashBody, fmt.Sprintf("-%x", h.Sum(nil)))
}
}
}

return rq
return req.WithContext(ctx)
}

var _ ctx = (*graphQLContext)(nil)

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

2 changes: 1 addition & 1 deletion plugins/traefik/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ github.com/coreos/go-systemd/v22/journal
# github.com/darkweak/go-esi v0.0.5
## explicit; go 1.18
github.com/darkweak/go-esi/esi
# github.com/darkweak/souin v1.6.34 => ../..
# github.com/darkweak/souin v1.6.35 => ../..
## explicit; go 1.16
github.com/darkweak/souin/cache/providers
github.com/darkweak/souin/cache/types
Expand Down
4 changes: 2 additions & 2 deletions plugins/tyk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/TykTechnologies/tyk v1.9.2-0.20220905191535-f610431668e4
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
github.com/eclipse/paho.mqtt.golang v1.4.1 // indirect
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
github.com/gobwas/ws v1.1.0 // indirect
Expand All @@ -32,4 +32,4 @@ require (
gorm.io/gorm v1.23.9 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..
4 changes: 2 additions & 2 deletions plugins/webgo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/bnkamalesh/webgo/v6 v6.7.0
github.com/darkweak/souin v1.6.34
github.com/darkweak/souin v1.6.35
)

require (
Expand Down Expand Up @@ -83,4 +83,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.34 => ../..
replace github.com/darkweak/souin v1.6.35 => ../..

0 comments on commit 2e3394c

Please sign in to comment.