forked from Ivasoft/traefik
Redirection: permanent move option.
This commit is contained in:
committed by
Traefiker
parent
c944d203fb
commit
58d6681824
@@ -33,6 +33,7 @@ const (
|
||||
pathFrontendRedirectEntryPoint = "/redirect/entrypoint"
|
||||
pathFrontendRedirectRegex = "/redirect/regex"
|
||||
pathFrontendRedirectReplacement = "/redirect/replacement"
|
||||
pathFrontendRedirectPermanent = "/redirect/permanent"
|
||||
pathFrontendErrorPages = "/errors/"
|
||||
pathFrontendErrorPagesBackend = "/backend"
|
||||
pathFrontendErrorPagesQuery = "/query"
|
||||
|
||||
@@ -108,9 +108,12 @@ func (p *Provider) getStickinessCookieName(rootPath string) string {
|
||||
}
|
||||
|
||||
func (p *Provider) getRedirect(rootPath string) *types.Redirect {
|
||||
permanent := p.getBool(false, rootPath, pathFrontendRedirectPermanent)
|
||||
|
||||
if p.has(rootPath, pathFrontendRedirectEntryPoint) {
|
||||
return &types.Redirect{
|
||||
EntryPoint: p.get("", rootPath, pathFrontendRedirectEntryPoint),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +121,7 @@ func (p *Provider) getRedirect(rootPath string) *types.Redirect {
|
||||
return &types.Redirect{
|
||||
Regex: p.get("", rootPath, pathFrontendRedirectRegex),
|
||||
Replacement: p.get("", rootPath, pathFrontendRedirectReplacement),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
||||
withPair(pathFrontendRedirectEntryPoint, "https"),
|
||||
withPair(pathFrontendRedirectRegex, "nope"),
|
||||
withPair(pathFrontendRedirectReplacement, "nope"),
|
||||
withPair(pathFrontendRedirectPermanent, "true"),
|
||||
withErrorPage("foo", "error", "/test1", "500-501, 503-599"),
|
||||
withErrorPage("bar", "error", "/test2", "400-405"),
|
||||
withRateLimit("client.ip",
|
||||
@@ -186,6 +187,7 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
||||
BasicAuth: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"},
|
||||
Redirect: &types.Redirect{
|
||||
EntryPoint: "https",
|
||||
Permanent: true,
|
||||
},
|
||||
Errors: map[string]*types.ErrorPage{
|
||||
"foo": {
|
||||
@@ -1044,6 +1046,18 @@ func TestProviderGetRedirect(t *testing.T) {
|
||||
EntryPoint: "https",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should use entry point when entry point key is valued in the store (permanent)",
|
||||
rootPath: "traefik/frontends/foo",
|
||||
kvPairs: filler("traefik",
|
||||
frontend("foo",
|
||||
withPair(pathFrontendRedirectEntryPoint, "https"),
|
||||
withPair(pathFrontendRedirectPermanent, "true"))),
|
||||
expected: &types.Redirect{
|
||||
EntryPoint: "https",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should use regex when regex keys are valued in the store",
|
||||
rootPath: "traefik/frontends/foo",
|
||||
@@ -1056,6 +1070,20 @@ func TestProviderGetRedirect(t *testing.T) {
|
||||
Replacement: "$1",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should use regex when regex keys are valued in the store (permanent)",
|
||||
rootPath: "traefik/frontends/foo",
|
||||
kvPairs: filler("traefik",
|
||||
frontend("foo",
|
||||
withPair(pathFrontendRedirectRegex, "(.*)"),
|
||||
withPair(pathFrontendRedirectReplacement, "$1"),
|
||||
withPair(pathFrontendRedirectPermanent, "true"))),
|
||||
expected: &types.Redirect{
|
||||
Regex: "(.*)",
|
||||
Replacement: "$1",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should only use entry point when entry point and regex base are valued in the store",
|
||||
rootPath: "traefik/frontends/foo",
|
||||
|
||||
Reference in New Issue
Block a user