This commit is contained in:
lif 2026-02-03 20:01:20 +01:00 committed by GitHub
commit 621f0b64c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 1 deletions

View file

@ -0,0 +1,30 @@
{
"http": {
"routers": {
"web-to-websecure": {
"entryPoints": [
"web"
],
"middlewares": [
"redirect-web-to-websecure"
],
"service": "noop@internal",
"rule": "HostRegexp(`^.+$`)",
"ruleSyntax": "default"
}
},
"services": {
"noop": {}
},
"middlewares": {
"redirect-web-to-websecure": {
"redirectScheme": {
"scheme": "https",
"permanent": true
}
}
}
},
"tcp": {},
"tls": {}
}

View file

@ -209,7 +209,14 @@ func (i *Provider) getEntryPointPort(name string, def *static.Redirections) (str
return "", fmt.Errorf("'to' entry point field references a non-existing entry point: %s", def.EntryPoint.To)
}
_, port, err := net.SplitHostPort(dst.GetAddress())
address := dst.GetAddress()
if address == "" {
// When address is empty (e.g., socket activation), return empty port.
// The redirect middleware will use the scheme's default port.
return "", nil
}
_, port, err := net.SplitHostPort(address)
if err != nil {
return "", fmt.Errorf("invalid entry point %q address %q: %w",
name, i.staticCfg.EntryPoints[def.EntryPoint.To].Address, err)

View file

@ -261,6 +261,28 @@ func Test_createConfiguration(t *testing.T) {
},
},
},
{
desc: "redirection_empty_address.json",
staticCfg: static.Configuration{
EntryPoints: map[string]*static.EntryPoint{
"web": {
Address: "",
HTTP: static.HTTPConfig{
Redirections: &static.Redirections{
EntryPoint: &static.RedirectEntryPoint{
To: "websecure",
Scheme: "https",
Permanent: true,
},
},
},
},
"websecure": {
Address: "",
},
},
},
},
}
for _, test := range testCases {