Skip to content

Commit

Permalink
IsLocalHost: support host:port
Browse files Browse the repository at this point in the history
Without this patch IsLocalHost does not work for URLs with port specified i.e. it works for `http://localhost` but does not work for `http://localhost:80` or `http://localhost:10000`.

Fixes #487
  • Loading branch information
mmatczuk committed Nov 7, 2022
1 parent a0805db commit 7ee4701
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ var localHostIpv4 = regexp.MustCompile(`127\.0\.0\.\d+`)
// IsLocalHost checks whether the destination host is explicitly local host
// (buggy, there can be IPv6 addresses it doesn't catch)
var IsLocalHost ReqConditionFunc = func(req *http.Request, ctx *ProxyCtx) bool {
return req.URL.Host == "::1" ||
req.URL.Host == "0:0:0:0:0:0:0:1" ||
localHostIpv4.MatchString(req.URL.Host) ||
req.URL.Host == "localhost"
h := req.URL.Hostname()
return h == "::1" || h == "0:0:0:0:0:0:0:1" || localHostIpv4.MatchString(h) || h == "localhost"
}

// UrlMatches returns a ReqCondition testing whether the destination URL
Expand Down

0 comments on commit 7ee4701

Please sign in to comment.