HTTP load generator, ApacheBench (ab) replacement
Go
ServerName should not contain a port.
Burcu Dogancf6f99598d13
diff --git a/boom.go b/boom.goindex cd241cc..612d9e5 100644--- a/boom.go+++ b/boom.go@@ -105,7 +105,7 @@ func main() {}var (- url, method, serverName string+ url, method, originalHost string// Username and password for basic authusername, password string// request headers@@ -113,7 +113,7 @@ func main() {)method = strings.ToUpper(*flagMethod)- url, serverName = resolveUrl(flag.Args()[0])+ url, originalHost = resolveUrl(flag.Args()[0])// set content-typeheader.Set("Content-Type", *flagType)@@ -147,13 +147,13 @@ func main() {(&commands.Boom{Req: &commands.ReqOpts{- Method: method,- Url: url,- Body: *flagD,- Header: header,- Username: username,- Password: password,- ServerName: serverName,+ Method: method,+ Url: url,+ Body: *flagD,+ Header: header,+ Username: username,+ Password: password,+ OriginalHost: originalHost,},N: n,C: c,@@ -180,6 +180,7 @@ func resolveUrl(url string) (string, string) {if err != nil {usageAndExit(err.Error())}+ originalHost := uri.HostserverName, port, err := net.SplitHostPort(uri.Host)if err != nil {@@ -203,7 +204,7 @@ func resolveUrl(url string) (string, string) {uri.Host = fmt.Sprintf("[%s]", ip)}}- return uri.String(), serverName+ return uri.String(), originalHost}func usageAndExit(message string) {diff --git a/boom_test.go b/boom_test.goindex f7d792a..dbc24d1 100644--- a/boom_test.go+++ b/boom_test.go@@ -48,7 +48,7 @@ func TestParseUrl_IPv4(t *testing.T) {func TestParseUrl_IPv4AndPort(t *testing.T) {defaultDnsResolver = &mockDnsResolver{Addr: "127.0.0.1"}u, s := resolveUrl("http://google.com:80")- if s != "google.com" {+ if s != "google.com:80" {t.Errorf("Original server name doesn't match with google.com, %v is found.", s)}if u != "http://127.0.0.1:80" {@@ -70,7 +70,7 @@ func TestParseUrl_IPv6(t *testing.T) {func TestParseUrl_IPv6AndPort(t *testing.T) {defaultDnsResolver = &mockDnsResolver{Addr: "2a00:1450:400a:806::1007"}u, s := resolveUrl("http://google.com:80")- if s != "google.com" {+ if s != "google.com:80" {t.Errorf("Original server name doesn't match with google.com, %v is found.", s)}if u != "http://[2a00:1450:400a:806::1007]:80" {diff --git a/commands/boom.go b/commands/boom.goindex 6bf8347..6b30b38 100644--- a/commands/boom.go+++ b/commands/boom.go@@ -38,7 +38,7 @@ type ReqOpts struct {Password string// Request host is an resolved IP. TLS/SSL handshakes may require// the original server name, keep it to initate the TLS client.- ServerName string+ OriginalHost string}// Creates a req object from req options@@ -47,7 +47,7 @@ func (r *ReqOpts) Request() *http.Request {req.Header = r.Header// update the Host value in the Request - this is used as the host header in any subsequent request- req.Host = r.ServerName+ req.Host = r.OriginalHostif r.Username != "" && r.Password != "" {req.SetBasicAuth(r.Username, r.Password)diff --git a/commands/run.go b/commands/run.goindex c6f65c9..15283ae 100644--- a/commands/run.go+++ b/commands/run.go@@ -16,6 +16,7 @@ package commandsimport ("crypto/tls"+ "net""net/http""sync""time"@@ -31,8 +32,9 @@ func (b *Boom) Run() {}func (b *Boom) worker(ch chan *http.Request) {+ host, _, _ := net.SplitHostPort(b.Req.OriginalHost)tr := &http.Transport{- TLSClientConfig: &tls.Config{InsecureSkipVerify: b.AllowInsecure, ServerName: b.Req.ServerName},+ TLSClientConfig: &tls.Config{InsecureSkipVerify: b.AllowInsecure, ServerName: host},}client := &http.Client{Transport: tr}for req := range ch {