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