core/config: add support for stripping the port for matching routes (#5085)

* core/config: add support for stripping the port for matching routes

* fix test

* rename option, improve port detection

* add more test cases
This commit is contained in:
Caleb Doxsey 2024-04-26 08:24:46 -06:00 committed by GitHub
parent 498c3aa108
commit 5373e25ac4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 100 additions and 34 deletions

View file

@ -106,9 +106,9 @@ func GetServerNamesForURL(u *url.URL) []string {
// GetDomainsForURL returns the available domains for given url.
//
// For standard HTTP (80)/HTTPS (443) ports, it returns `example.com` and `example.com:<port>`.
// Otherwise, return the URL.Host value.
func GetDomainsForURL(u *url.URL) []string {
// For standard HTTP (80)/HTTPS (443) ports, it returns `example.com` and `example.com:<port>`,
// if includeDefaultPort is set. Otherwise, return the URL.Host value.
func GetDomainsForURL(u *url.URL, includeDefaultPort bool) []string {
if u == nil {
return nil
}
@ -141,6 +141,10 @@ func GetDomainsForURL(u *url.URL) []string {
}
}
if !includeDefaultPort {
return []string{u.Hostname()}
}
// for everything else we return two routes: 'example.com' and 'example.com:443'
return []string{u.Hostname(), net.JoinHostPort(u.Hostname(), defaultPort)}
}