Skip to content

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
wzv5 committed Jul 21, 2023
1 parent b0c24d2 commit b3cf11e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/ping/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ func (this *HttpPing) PingContext(ctx context.Context) IPingResult {
return this.errorResult(err)
}
}
ipstr := ip.String()
if isIPv6(ip) {
ipstr = fmt.Sprintf("[%s]", ipstr)
}
if port != "" {
u.Host = net.JoinHostPort(ip.String(), port)
u.Host = fmt.Sprintf("%s:%s", ipstr, port)
} else {
u.Host = ip.String()
u.Host = ipstr
}
url2 := u.String()

Expand Down
9 changes: 9 additions & 0 deletions test/pping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ func TestQuic(t *testing.T) {
t.Fatal(result.Error())
}
}

func TestHttpIPv6(t *testing.T) {
p := ping.NewHttpPing("GET", "https://www.qq.com/", time.Second*5)
p.IP, _ = ping.LookupIPv6("www.qq.com")
result := p.Ping()
if result.Error() != nil {
t.Fatal(result.Error())
}
}

0 comments on commit b3cf11e

Please sign in to comment.