Fixed stripPrefix middleware is not applied to retried attempts
This commit is contained in:
parent
789046f162
commit
f4ddf25e41
3 changed files with 65 additions and 1 deletions
40
integration/fixtures/retry/strip_prefix.toml
Normal file
40
integration/fixtures/retry/strip_prefix.toml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
[global]
|
||||||
|
checkNewVersion = false
|
||||||
|
sendAnonymousUsage = false
|
||||||
|
|
||||||
|
[log]
|
||||||
|
level = "DEBUG"
|
||||||
|
|
||||||
|
[entryPoints]
|
||||||
|
[entryPoints.web]
|
||||||
|
address = ":8000"
|
||||||
|
|
||||||
|
[api]
|
||||||
|
insecure = true
|
||||||
|
|
||||||
|
[providers.file]
|
||||||
|
filename = "{{ .SelfFilename }}"
|
||||||
|
|
||||||
|
## dynamic configuration ##
|
||||||
|
|
||||||
|
[http.routers]
|
||||||
|
[http.routers.router1]
|
||||||
|
service = "service1"
|
||||||
|
middlewares = [ "retry", "strip-prefix" ]
|
||||||
|
rule = "PathPrefix(`/`)"
|
||||||
|
|
||||||
|
[http.middlewares.retry.retry]
|
||||||
|
attempts = 3
|
||||||
|
|
||||||
|
[http.middlewares.strip-prefix.stripPrefix]
|
||||||
|
prefixes = [ "/test" ]
|
||||||
|
|
||||||
|
[http.services]
|
||||||
|
[http.services.service1]
|
||||||
|
[http.services.service1.loadBalancer]
|
||||||
|
|
||||||
|
[[http.services.service1.loadBalancer.servers]]
|
||||||
|
url = "http://{{ .WhoamiIP }}:8080"
|
||||||
|
|
||||||
|
[[http.services.service1.loadBalancer.servers]]
|
||||||
|
url = "http://{{ .WhoamiIP }}:80"
|
|
@ -1,6 +1,7 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
@ -86,3 +87,26 @@ func (s *RetrySuite) TestRetryWebsocket(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(response.StatusCode, checker.Equals, http.StatusSwitchingProtocols)
|
c.Assert(response.StatusCode, checker.Equals, http.StatusSwitchingProtocols)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *RetrySuite) TestRetryWithStripPrefix(c *check.C) {
|
||||||
|
file := s.adaptFile(c, "fixtures/retry/strip_prefix.toml", struct{ WhoamiIP string }{s.whoamiIP})
|
||||||
|
defer os.Remove(file)
|
||||||
|
|
||||||
|
cmd, display := s.traefikCmd(withConfigFile(file))
|
||||||
|
defer display(c)
|
||||||
|
err := cmd.Start()
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
defer s.killCmd(cmd)
|
||||||
|
|
||||||
|
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 60*time.Second, try.BodyContains("PathPrefix(`/`)"))
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
response, err := http.Get("http://127.0.0.1:8000/test")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
body, err := io.ReadAll(response.Body)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
c.Assert(string(body), checker.Contains, "GET / HTTP/1.1")
|
||||||
|
c.Assert(string(body), checker.Contains, "X-Forwarded-Prefix: /test")
|
||||||
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ func (r *retry) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
newCtx := httptrace.WithClientTrace(req.Context(), trace)
|
newCtx := httptrace.WithClientTrace(req.Context(), trace)
|
||||||
|
|
||||||
r.next.ServeHTTP(retryResponseWriter, req.WithContext(newCtx))
|
r.next.ServeHTTP(retryResponseWriter, req.Clone(newCtx))
|
||||||
|
|
||||||
if !retryResponseWriter.ShouldRetry() {
|
if !retryResponseWriter.ShouldRetry() {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue