fix addr judge
This commit is contained in:
parent
61a2d6a6ba
commit
d177f3df69
@ -179,13 +179,19 @@ func (bp *Bypass) Contains(addr string) bool {
|
||||
if ip == nil {
|
||||
// avoid long time lookupIP
|
||||
// invalid domain when CI
|
||||
if u, err := url.ParseRequestURI(addr); err == nil {
|
||||
if _, _, ok := net.ParseCIDR(addr); ok != nil {
|
||||
newAddr := addr
|
||||
if strings.Index(addr, "http://") == -1 && strings.Index(addr, "https://") == -1 {
|
||||
newAddr = "http://" + addr
|
||||
}
|
||||
if u, err := url.Parse(newAddr); err == nil {
|
||||
if ipArr, err := net.LookupIP(u.Hostname()); err == nil {
|
||||
for _, ip := range ipArr {
|
||||
ips = append(ips, fmt.Sprintf("%v", ip))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ips = append(ips, fmt.Sprintf("%v", ip))
|
||||
}
|
||||
|
@ -174,8 +174,8 @@ var bypassContainTests = []struct {
|
||||
|
||||
{CNIP, false, "http://www.baidu.com", true},
|
||||
{CNIP, false, "http://www.google.com", false},
|
||||
{CNIP, true, "http://www.jd.com", false},
|
||||
{CNIP, true, "http://www.facebook.com", true},
|
||||
{CNIP, true, "www.jd.com", false},
|
||||
{CNIP, true, "www.facebook.com", true},
|
||||
}
|
||||
|
||||
func TestBypassContains(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user