Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 647 NormalizeHost #648

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions route/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ func (t Table) route(host, path string) *Route {
// normalizeHost returns the hostname from the request
// and removes the default port if present.
func normalizeHost(host string, tls bool) string {
host = strings.ToLower(host)
return strings.ToLower(normalizeHostNoLower(host, tls))
}

func normalizeHostNoLower(host string, tls bool) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should change normalizeHost to use this new function:

func normalizeHost(host string, tls bool) string {
    return strings.ToLower(normalizeHostNoLower(host, tls))
}

if !tls && strings.HasSuffix(host, ":80") {
return host[:len(host)-len(":80")]
}
Expand Down Expand Up @@ -355,13 +358,12 @@ func (t Table) matchingHosts(req *http.Request) (hosts []string) {
// matchingHostNoGlob returns the route from the
// routing table which matches the normalized request hostname.
func (t Table) matchingHostNoGlob(req *http.Request) (hosts []string) {
host := normalizeHost(req.Host, req.TLS != nil)
host := normalizeHostNoLower(req.Host, req.TLS != nil)

for pattern := range t {
normpat := normalizeHost(pattern, req.TLS != nil)
if normpat == host {
//log.Printf("DEBUG Matched %s and %s", normpat, host)
hosts = append(hosts, pattern)
if normpat == host {
hosts = append(hosts, strings.ToLower(pattern))
return
}
}
Expand Down