mirror of
https://github.com/traefik/traefik.git
synced 2026-05-05 12:26:25 +02:00
Fix from to www nginx annotation
This commit is contained in:
parent
1ee0c8b4f0
commit
fc65ec8839
@ -138,6 +138,51 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||
expectedURL: "https://foo",
|
||||
expectedStatus: http.StatusTemporaryRedirect,
|
||||
},
|
||||
{
|
||||
desc: "www-redirect without port",
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: "$1://example.com$2/$3",
|
||||
Permanent: true,
|
||||
},
|
||||
url: "http://www.example.com/path",
|
||||
expectedURL: "http://example.com/path",
|
||||
expectedStatus: http.StatusMovedPermanently,
|
||||
},
|
||||
{
|
||||
desc: "www-redirect with port",
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: "$1://example.com$2/$3",
|
||||
Permanent: true,
|
||||
},
|
||||
url: "http://www.example.com:8080/path",
|
||||
expectedURL: "http://example.com:8080/path",
|
||||
expectedStatus: http.StatusMovedPermanently,
|
||||
},
|
||||
{
|
||||
desc: "www-redirect without port, root path",
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: "$1://example.com$2/$3",
|
||||
Permanent: true,
|
||||
},
|
||||
url: "http://www.example.com/",
|
||||
expectedURL: "http://example.com/",
|
||||
expectedStatus: http.StatusMovedPermanently,
|
||||
},
|
||||
{
|
||||
desc: "www-redirect HTTPS without port",
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: "$1://example.com$2/$3",
|
||||
Permanent: true,
|
||||
},
|
||||
secured: true,
|
||||
url: "https://www.example.com/path",
|
||||
expectedURL: "https://example.com/path",
|
||||
expectedStatus: http.StatusMovedPermanently,
|
||||
},
|
||||
{
|
||||
desc: "HTTP to HTTP POST permanent",
|
||||
config: dynamic.RedirectRegex{
|
||||
|
||||
@ -1164,9 +1164,9 @@ func applyFromToWwwRedirect(hosts map[string]bool, ruleHost, routerName string,
|
||||
fromToWwwRedirectMiddlewareName := routerName + "-from-to-www-redirect"
|
||||
conf.HTTP.Middlewares[fromToWwwRedirectMiddlewareName] = &dynamic.Middleware{
|
||||
RedirectRegex: &dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/]+:([0-9]+)/(.*)`,
|
||||
Replacement: fmt.Sprintf("$1://%s:$2/$3", ruleHost),
|
||||
Permanent: true,
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: fmt.Sprintf("$1://%s$2/$3", ruleHost),
|
||||
StatusCode: ptr.To(http.StatusPermanentRedirect),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -1238,9 +1238,9 @@ func TestLoadIngresses(t *testing.T) {
|
||||
Middlewares: map[string]*dynamic.Middleware{
|
||||
"default-ingress-with-www-host-rule-0-path-0-from-to-www-redirect": {
|
||||
RedirectRegex: &dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/]+:([0-9]+)/(.*)`,
|
||||
Replacement: "$1://www.host.localhost:$2/$3",
|
||||
Permanent: true,
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: "$1://www.host.localhost$2/$3",
|
||||
StatusCode: ptr.To(http.StatusPermanentRedirect),
|
||||
},
|
||||
},
|
||||
"default-ingress-with-www-host-rule-0-path-0-retry": {
|
||||
@ -1312,9 +1312,9 @@ func TestLoadIngresses(t *testing.T) {
|
||||
Middlewares: map[string]*dynamic.Middleware{
|
||||
"default-ingress-with-host-rule-0-path-0-from-to-www-redirect": {
|
||||
RedirectRegex: &dynamic.RedirectRegex{
|
||||
Regex: `(https?)://[^/]+:([0-9]+)/(.*)`,
|
||||
Replacement: "$1://host.localhost:$2/$3",
|
||||
Permanent: true,
|
||||
Regex: `(https?)://[^/:]+(:[0-9]+)?/(.*)`,
|
||||
Replacement: "$1://host.localhost$2/$3",
|
||||
StatusCode: ptr.To(http.StatusPermanentRedirect),
|
||||
},
|
||||
},
|
||||
"default-ingress-with-host-rule-0-path-0-retry": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user