HTTP load generator, ApacheBench (ab) replacement
Go
Adding timeout flag.
Burcu Dogane45d95ff3a9e
diff --git a/README.md b/README.mdindex f358e7f..acd678c 100644--- a/README.md+++ b/README.md@@ -29,6 +29,7 @@ Options:-m HTTP method, one of GET, POST, PUT, DELETE, HEAD, OPTIONS.-h Custom HTTP headers, name1:value1;name2:value2.+ -t Timeout in ms.-A HTTP Accept header.-d HTTP request body.-T Content-type, defaults to "text/html".diff --git a/boom.go b/boom.goindex 986d89a..0aeee76 100644--- a/boom.go+++ b/boom.go@@ -69,6 +69,7 @@ Options:-m HTTP method, one of GET, POST, PUT, DELETE, HEAD, OPTIONS.-h Custom HTTP headers, name1:value1;name2:value2.+ -t Timeout in ms.-A HTTP Accept header.-d HTTP request body.-T Content-type, defaults to "text/html".diff --git a/boomer/run.go b/boomer/run.goindex 34f6345..92842f9 100644--- a/boomer/run.go+++ b/boomer/run.go@@ -39,6 +39,9 @@ func (b *Boomer) worker(ch chan *http.Request) {TLSClientConfig: &tls.Config{InsecureSkipVerify: b.AllowInsecure, ServerName: host},DisableCompression: b.DisableCompression,DisableKeepAlives: b.DisableKeepAlives,+ Dial: (&net.Dialer{+ Timeout: time.Duration(b.Timeout) * time.Millisecond,+ }).Dial,}if b.ProxyAddr != "" {tr.Dial = func(network string, addr string) (conn net.Conn, err error) {@@ -51,12 +54,11 @@ func (b *Boomer) worker(ch chan *http.Request) {resp, err := client.Do(req)code := 0var size int64 = -1- if resp != nil {+ if err == nil {code = resp.StatusCodeif resp.ContentLength > 0 {size = resp.ContentLength}- // consume the whole bodyio.Copy(ioutil.Discard, resp.Body)// cleanup body, so the socket can be reusableresp.Body.Close()