diff --git a/middlewares/redirect/redirect.go b/middlewares/redirect/redirect.go index 5508669e7..e7a5c6346 100644 --- a/middlewares/redirect/redirect.go +++ b/middlewares/redirect/redirect.go @@ -17,7 +17,7 @@ import ( ) const ( - defaultRedirectRegex = `^(?:https?:\/\/)?([\w\._-]+)(?::\d+)?(.*)$` + defaultRedirectRegex = `^(?:https?:\/\/)?(\[[\w:.]+\]|[\w\._-]+)(?::\d+)?(.*)$` ) // NewEntryPointHandler create a new redirection handler base on entry point diff --git a/middlewares/redirect/redirect_test.go b/middlewares/redirect/redirect_test.go index d7b61e4cc..4f938053b 100644 --- a/middlewares/redirect/redirect_test.go +++ b/middlewares/redirect/redirect_test.go @@ -84,6 +84,34 @@ func TestNewEntryPointHandler(t *testing.T) { url: "http://foo:80", errorExpected: true, }, + { + desc: "IPV6 HTTP to HTTP", + entryPoint: &configuration.EntryPoint{Address: ":8080"}, + url: "http://[::1]", + expectedURL: "http://[::1]:8080", + expectedStatus: http.StatusFound, + }, + { + desc: "IPV6 HTTP to HTTPS", + entryPoint: &configuration.EntryPoint{Address: ":443", TLS: &tls.TLS{}}, + url: "http://[::1]", + expectedURL: "https://[::1]:443", + expectedStatus: http.StatusFound, + }, + { + desc: "IPV6 HTTP with port 80 to HTTP", + entryPoint: &configuration.EntryPoint{Address: ":8080"}, + url: "http://[::1]:80", + expectedURL: "http://[::1]:8080", + expectedStatus: http.StatusFound, + }, + { + desc: "IPV6 HTTP with port 80 to HTTPS", + entryPoint: &configuration.EntryPoint{Address: ":443", TLS: &tls.TLS{}}, + url: "http://[::1]:80", + expectedURL: "https://[::1]:443", + expectedStatus: http.StatusFound, + }, } for _, test := range testCases {