Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Fix proxying.

Burcu Dogan6c2688636758
diff --git a/boom.go b/boom.go
index 0aeee76..96de8b1 100644
--- a/boom.go
+++ b/boom.go
@@ -161,10 +161,19 @@ func main() {
usageAndExit("Invalid output type.")
}
+ var proxyURL *gourl.URL
+ if *proxyAddr != "" {
+ var err error
+ proxyURL, err = gourl.Parse(*proxyAddr)
+ if err != nil {
+ usageAndExit(err.Error())
+ }
+ }
+
(&boomer.Boomer{
Req: &boomer.ReqOpts{
Method: method,
- Url: url,
+ URL: url,
Body: *body,
Header: header,
Username: username,
@@ -178,7 +187,7 @@ func main() {
AllowInsecure: *insecure,
DisableCompression: *disableCompression,
DisableKeepAlives: *disableKeepAlives,
- ProxyAddr: *proxyAddr,
+ ProxyAddr: proxyURL,
Output: *output,
}).Run()
}
diff --git a/boom_test.go b/boom_test.go
index 15fb560..ea44bb1 100644
--- a/boom_test.go
+++ b/boom_test.go
@@ -26,7 +26,7 @@ func (r *mockDnsResolver) Lookup(host string) ([]string, error) {
return []string{r.Addr}, nil
}
-func TestParseUrl(t *testing.T) {
+func TestParseURL(t *testing.T) {
defaultDNSResolver = &mockDnsResolver{Addr: "2a00:1450:400a:806::1007"}
u, _ := resolveUrl("http://google.com:80/path/to/resource?q=rawquery")
if u != "http://[2a00:1450:400a:806::1007]:80/path/to/resource?q=rawquery" {
diff --git a/boomer/boomer.go b/boomer/boomer.go
index 0ca0388..cac0f18 100644
--- a/boomer/boomer.go
+++ b/boomer/boomer.go
@@ -17,6 +17,7 @@ package boomer
import (
"net/http"
+ "net/url"
"strings"
"time"
@@ -32,7 +33,7 @@ type result struct {
type ReqOpts struct {
Method string
- Url string
+ URL string
Header http.Header
Body string
Username string
@@ -45,7 +46,7 @@ type ReqOpts struct {
// Creates a req object from req options
func (r *ReqOpts) Request() *http.Request {
- req, _ := http.NewRequest(r.Method, r.Url, strings.NewReader(r.Body))
+ req, _ := http.NewRequest(r.Method, r.URL, strings.NewReader(r.Body))
req.Header = r.Header
// update the Host value in the Request - this is used as the host header in any subsequent request
@@ -89,7 +90,7 @@ type Boomer struct {
// ProxyAddr is the address of HTTP proxy server in the format on "host:port".
// Optional.
- ProxyAddr string
+ ProxyAddr *url.URL
bar *pb.ProgressBar
results chan *result
diff --git a/boomer/run.go b/boomer/run.go
index 9dc790b..0ed129e 100644
--- a/boomer/run.go
+++ b/boomer/run.go
@@ -53,11 +53,7 @@ func (b *Boomer) worker(wg *sync.WaitGroup, ch chan *http.Request) {
DisableKeepAlives: b.DisableKeepAlives,
// TODO(jbd): Add dial timeout.
TLSHandshakeTimeout: time.Duration(b.Timeout) * time.Millisecond,
- }
- if b.ProxyAddr != "" {
- tr.Dial = func(network string, addr string) (conn net.Conn, err error) {
- return net.Dial(network, b.ProxyAddr)
- }
+ Proxy: http.ProxyURL(b.ProxyAddr),
}
client := &http.Client{Transport: tr}
_ = client
diff --git a/boomer/run_test.go b/boomer/run_test.go
index acd44d1..9512e51 100644
--- a/boomer/run_test.go
+++ b/boomer/run_test.go
@@ -35,7 +35,7 @@ func TestN(t *testing.T) {
boomer := &Boomer{
Req: &ReqOpts{
Method: "GET",
- Url: server.URL,
+ URL: server.URL,
},
N: 20,
C: 2,
@@ -58,7 +58,7 @@ func TestQps(t *testing.T) {
boomer := &Boomer{
Req: &ReqOpts{
Method: "GET",
- Url: server.URL,
+ URL: server.URL,
},
N: 20,
C: 2,
@@ -93,7 +93,7 @@ func TestRequest(t *testing.T) {
boomer := &Boomer{
Req: &ReqOpts{
Method: "PUT",
- Url: server.URL,
+ URL: server.URL,
Header: header,
Username: "username",
Password: "password",
@@ -130,7 +130,7 @@ func TestBody(t *testing.T) {
boomer := &Boomer{
Req: &ReqOpts{
Method: "POST",
- Url: server.URL,
+ URL: server.URL,
Body: "Body",
},
N: 10,