Skip to content

Commit b3cf11e

Browse files
committed
fix #4
1 parent b0c24d2 commit b3cf11e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/ping/http.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ func (this *HttpPing) PingContext(ctx context.Context) IPingResult {
7474
return this.errorResult(err)
7575
}
7676
}
77+
ipstr := ip.String()
78+
if isIPv6(ip) {
79+
ipstr = fmt.Sprintf("[%s]", ipstr)
80+
}
7781
if port != "" {
78-
u.Host = net.JoinHostPort(ip.String(), port)
82+
u.Host = fmt.Sprintf("%s:%s", ipstr, port)
7983
} else {
80-
u.Host = ip.String()
84+
u.Host = ipstr
8185
}
8286
url2 := u.String()
8387

test/pping_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,12 @@ func TestQuic(t *testing.T) {
9999
t.Fatal(result.Error())
100100
}
101101
}
102+
103+
func TestHttpIPv6(t *testing.T) {
104+
p := ping.NewHttpPing("GET", "https://www.qq.com/", time.Second*5)
105+
p.IP, _ = ping.LookupIPv6("www.qq.com")
106+
result := p.Ping()
107+
if result.Error() != nil {
108+
t.Fatal(result.Error())
109+
}
110+
}

0 commit comments

Comments
 (0)