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

Fix DstHostIs check #608

Merged
merged 2 commits into from
Dec 30, 2024
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
19 changes: 18 additions & 1 deletion dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,26 @@ func UrlMatches(re *regexp.Regexp) ReqConditionFunc {

// DstHostIs returns a ReqCondition testing wether the host in the request url is the given string.
func DstHostIs(host string) ReqConditionFunc {
// Make sure to perform a case-insensitive host check
host = strings.ToLower(host)
var port string

// Check if the user specified a custom port that we need to match
if strings.Contains(host, ":") {
hostOnly, portOnly, err := net.SplitHostPort(host)
if err == nil {
host = hostOnly
port = portOnly
}
}

return func(req *http.Request, ctx *ProxyCtx) bool {
return strings.ToLower(req.URL.Host) == host
// Check port matching only if it was specified
if port != "" && port != req.URL.Port() {
return false
}

return strings.ToLower(req.URL.Hostname()) == host
}
}

Expand Down
Loading