Add keepTrailingSlash option
This commit is contained in:
parent
70fa42aee0
commit
95d86d84b4
6 changed files with 100 additions and 2 deletions
|
@ -396,3 +396,51 @@ func (s *SimpleSuite) TestMultipleProviderSameBackendName(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
|
||||
}
|
||||
|
||||
func (s *SimpleSuite) TestDontKeepTrailingSlash(c *check.C) {
|
||||
file := s.adaptFile(c, "fixtures/keep_trailing_slash.toml", struct {
|
||||
KeepTrailingSlash bool
|
||||
}{false})
|
||||
defer os.Remove(file)
|
||||
|
||||
cmd, output := s.traefikCmd(withConfigFile(file))
|
||||
defer output(c)
|
||||
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
oldCheckRedirect := http.DefaultClient.CheckRedirect
|
||||
http.DefaultClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8000/test/foo/", 1*time.Second, try.StatusCodeIs(http.StatusMovedPermanently))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
http.DefaultClient.CheckRedirect = oldCheckRedirect
|
||||
}
|
||||
|
||||
func (s *SimpleSuite) TestKeepTrailingSlash(c *check.C) {
|
||||
file := s.adaptFile(c, "fixtures/keep_trailing_slash.toml", struct {
|
||||
KeepTrailingSlash bool
|
||||
}{true})
|
||||
defer os.Remove(file)
|
||||
|
||||
cmd, output := s.traefikCmd(withConfigFile(file))
|
||||
defer output(c)
|
||||
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
oldCheckRedirect := http.DefaultClient.CheckRedirect
|
||||
http.DefaultClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8000/test/foo/", 1*time.Second, try.StatusCodeIs(http.StatusNotFound))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
http.DefaultClient.CheckRedirect = oldCheckRedirect
|
||||
}
|
||||
|
|
23
integration/fixtures/keep_trailing_slash.toml
Normal file
23
integration/fixtures/keep_trailing_slash.toml
Normal file
|
@ -0,0 +1,23 @@
|
|||
defaultEntryPoints = ["http"]
|
||||
|
||||
keepTrailingSlash = {{ .KeepTrailingSlash }}
|
||||
[entryPoints]
|
||||
[entryPoints.http]
|
||||
address = ":8000"
|
||||
|
||||
logLevel = "DEBUG"
|
||||
|
||||
[file]
|
||||
|
||||
# rules
|
||||
[backends]
|
||||
[backends.backend1]
|
||||
[backends.backend1.servers.server1]
|
||||
url = "http://172.17.0.2:80"
|
||||
weight = 1
|
||||
|
||||
[frontends]
|
||||
[frontends.frontend1]
|
||||
backend = "backend1"
|
||||
[frontends.frontend1.routes.test_1]
|
||||
rule = "Path:/test/foo"
|
Loading…
Add table
Add a link
Reference in a new issue