Request buffering middleware
This commit is contained in:
parent
d426126a92
commit
a81171d5f1
44 changed files with 2155 additions and 5 deletions
|
@ -15,6 +15,12 @@ const (
|
|||
pathBackendServers = "/servers/"
|
||||
pathBackendServerURL = "/url"
|
||||
pathBackendServerWeight = "/weight"
|
||||
pathBackendBuffering = "/buffering/"
|
||||
pathBackendBufferingMaxResponseBodyBytes = pathBackendBuffering + "maxresponsebodybytes"
|
||||
pathBackendBufferingMemResponseBodyBytes = pathBackendBuffering + "memresponsebodybytes"
|
||||
pathBackendBufferingMaxRequestBodyBytes = pathBackendBuffering + "maxrequestbodybytes"
|
||||
pathBackendBufferingMemRequestBodyBytes = pathBackendBuffering + "memrequestbodybytes"
|
||||
pathBackendBufferingRetryExpression = pathBackendBuffering + "retryexpression"
|
||||
|
||||
pathFrontends = "/frontends/"
|
||||
pathFrontendBackend = "/backend"
|
||||
|
|
|
@ -60,6 +60,7 @@ func (p *Provider) buildConfiguration() *types.Configuration {
|
|||
"getLoadBalancer": p.getLoadBalancer,
|
||||
"getMaxConn": p.getMaxConn,
|
||||
"getHealthCheck": p.getHealthCheck,
|
||||
"getBuffering": p.getBuffering,
|
||||
"getSticky": p.getSticky, // Deprecated [breaking]
|
||||
"hasStickinessLabel": p.hasStickinessLabel, // Deprecated [breaking]
|
||||
"getStickinessCookieName": p.getStickinessCookieName, // Deprecated [breaking]
|
||||
|
@ -273,6 +274,25 @@ func (p *Provider) getHealthCheck(rootPath string) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Provider) getBuffering(rootPath string) *types.Buffering {
|
||||
pathsBuffering := p.list(rootPath, pathBackendBuffering)
|
||||
|
||||
var buffering *types.Buffering
|
||||
if len(pathsBuffering) > 0 {
|
||||
if buffering == nil {
|
||||
buffering = &types.Buffering{}
|
||||
}
|
||||
|
||||
buffering.MaxRequestBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMaxRequestBodyBytes)
|
||||
buffering.MaxResponseBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMaxResponseBodyBytes)
|
||||
buffering.MemRequestBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMemRequestBodyBytes)
|
||||
buffering.MemResponseBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMemResponseBodyBytes)
|
||||
buffering.RetryExpression = p.get("", rootPath, pathBackendBufferingRetryExpression)
|
||||
}
|
||||
|
||||
return buffering
|
||||
}
|
||||
|
||||
func (p *Provider) getTLSSection(prefix string) []*tls.Configuration {
|
||||
var tlsSection []*tls.Configuration
|
||||
|
||||
|
|
|
@ -76,6 +76,11 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
withPair(pathBackendHealthCheckInterval, "30s"),
|
||||
withPair(pathBackendMaxConnAmount, "5"),
|
||||
withPair(pathBackendMaxConnExtractorFunc, "client.ip"),
|
||||
withPair(pathBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
withPair("servers/server1/url", "http://172.17.0.2:80"),
|
||||
withPair("servers/server1/weight", "0"),
|
||||
withPair("servers/server2/weight", "0")),
|
||||
|
@ -162,6 +167,13 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
Port: 80,
|
||||
Interval: "30s",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
Frontends: map[string]*types.Frontend{
|
||||
|
@ -1700,6 +1712,47 @@ func TestProviderGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProviderGetBufferingReal(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
rootPath string
|
||||
kvPairs []*store.KVPair
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "when all configuration keys defined",
|
||||
rootPath: "traefik/backends/foo",
|
||||
kvPairs: filler("traefik",
|
||||
backend("foo",
|
||||
withPair(pathBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"))),
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
p := newProviderMock(test.kvPairs)
|
||||
|
||||
result := p.getBuffering(test.rootPath)
|
||||
|
||||
assert.Equal(t, test.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderGetTLSes(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue