Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Put square brackets only around IPv6s.

Burcu Dogan4cf9b9a16c6d
diff --git a/boom.go b/boom.go
index 82537d6..bbbeaa8 100644
--- a/boom.go
+++ b/boom.go
@@ -178,15 +178,18 @@ func newURL(url string) (*gourl.URL, string) {
if err != nil {
usageAndExit(err.Error())
}
-
+ ip := addrs[0]
if port != "" {
// join automatically puts square brackets around the
// ipv6 IPs.
- uri.Host = net.JoinHostPort(addrs[0], port)
+ uri.Host = net.JoinHostPort(ip, port)
} else {
+ uri.Host = ip
// square brackets are required for ipv6 IPs.
// otherwise, net.Dial fails with a parsing error.
- uri.Host = fmt.Sprintf("[%s]", addrs[0])
+ if strings.Contains(ip, ":") {
+ uri.Host = fmt.Sprintf("[%s]", ip)
+ }
}
return uri, serverName
}
diff --git a/boom_test.go b/boom_test.go
index 5adec24..cc5b101 100644
--- a/boom_test.go
+++ b/boom_test.go
@@ -40,7 +40,7 @@ func TestParseUrl_IPv4(t *testing.T) {
if s != "google.com" {
t.Errorf("Original server name doesn't match with google.com, %v is found.", s)
}
- if u.String() != "http://[127.0.0.1]" {
+ if u.String() != "http://127.0.0.1" {
t.Errorf("URL is expected to be http://127.0.0.1, %v is found.", u)
}
}