From 259b70a7dfe9714829da0da262111d5783dd87ef Mon Sep 17 00:00:00 2001 From: SaraRands Date: Wed, 5 Aug 2015 14:05:59 -0600 Subject: [PATCH 1/5] Added --http-original-host flag --- settings.go | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.go b/settings.go index dd2a000..3356797 100644 --- a/settings.go +++ b/settings.go @@ -90,6 +90,7 @@ func init() { flag.DurationVar(&Settings.outputHTTPConfig.Timeout, "output-http-timeout", 0, "Specify HTTP request/response timeout. By default 5s. Example: --output-http-timeout 30s") flag.BoolVar(&Settings.outputHTTPConfig.stats, "output-http-stats", false, "Report http output queue stats to console every 5 seconds.") + flag.BoolVar(&Settings.outputHTTPConfig.OriginalHost, "http-original-host", false, "Normally gor replaces the Host http header with the host supplied with --output-http. This option disables that behavior, preserving the original Host header.") flag.StringVar(&Settings.outputHTTPConfig.elasticSearch, "output-http-elasticsearch", "", "Send request and response stats to ElasticSearch:\n\tgor --input-raw :8080 --output-http staging.com --output-http-elasticsearch 'es_host:api_port/index_name'") From de6c41c731d666ef1a6d3398835a1383de48a4ad Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Thu, 6 Aug 2015 09:34:51 +0300 Subject: [PATCH 2/5] Update docs for Host header --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index b544ee2..2ea19c3 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,11 @@ gor --input-raw :80 --output-http "http://staging.server" \ --http-header "Enable-Feature-X: true" ``` +#### Host header +Host header gets special treatment. By default Host get set to the value specified in --output-http. If you manually set --http-header "Host: anonther.com", Gor will not override Host value. + +If you app accepts traffic from multiple domain, and you want to keep original headers, there is specific `--http-original-host` with tells Gor do not touch Host header at all. + ### Saving requests to file and replaying them You can save requests to file, and replay them later: ``` From d6b5c675cfeaeccd91b581f2d6437bd079bec979 Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Sun, 9 Aug 2015 11:07:27 +0300 Subject: [PATCH 3/5] Do not add 80 port to host string --- http_client.go | 10 ++++++++-- http_client_test.go | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/http_client.go b/http_client.go index 917c084..f9918b7 100644 --- a/http_client.go +++ b/http_client.go @@ -42,7 +42,9 @@ func NewHTTPClient(baseURL string, config *HTTPClientConfig) *HTTPClient { u, _ := url.Parse(baseURL) if !strings.Contains(u.Host, ":") { - u.Host += ":" + defaultPorts[u.Scheme] + if u.Scheme != "http" { + u.Host += ":" + defaultPorts[u.Scheme] + } } if config.Timeout.Nanoseconds() == 0 { @@ -66,7 +68,11 @@ func NewHTTPClient(baseURL string, config *HTTPClientConfig) *HTTPClient { func (c *HTTPClient) Connect() (err error) { c.Disconnect() - c.conn, err = net.Dial("tcp", c.host) + if !strings.Contains(c.host, ":") { + c.conn, err = net.Dial("tcp", c.host + ":80") + } else { + c.conn, err = net.Dial("tcp", c.host) + } if c.scheme == "https" { tlsConn := tls.Client(c.conn, &tls.Config{InsecureSkipVerify: true}) diff --git a/http_client_test.go b/http_client_test.go index d14d5be..6109a90 100644 --- a/http_client_test.go +++ b/http_client_test.go @@ -15,8 +15,8 @@ import ( func TestHTTPClientURLPort(t *testing.T) { c1 := NewHTTPClient("http://example.com", &HTTPClientConfig{}) - if c1.baseURL != "http://example.com:80" { - t.Error("Sould add 80 port for http:", c1.baseURL) + if c1.baseURL != "http://example.com" { + t.Error("Sould not add 80 port for http:", c1.baseURL) } c2 := NewHTTPClient("https://example.com", &HTTPClientConfig{}) @@ -30,8 +30,8 @@ func TestHTTPClientURLPort(t *testing.T) { } c4 := NewHTTPClient("example.com", &HTTPClientConfig{}) - if c4.baseURL != "http://example.com:80" { - t.Error("Sould add default protocol:", c4.baseURL) + if c4.baseURL != "http://example.com" { + t.Error("Sould not add default protocol:", c4.baseURL) } } From 9a76e354c5693ca560a108fbcb720936fc9de1fa Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Sun, 9 Aug 2015 11:08:53 +0300 Subject: [PATCH 4/5] Fix tcp input test --- input_tcp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input_tcp_test.go b/input_tcp_test.go index bbb0cc7..f440c57 100644 --- a/input_tcp_test.go +++ b/input_tcp_test.go @@ -40,7 +40,7 @@ func TestTCPInput(t *testing.T) { for i := 0; i < 100; i++ { wg.Add(1) - encoded := make([]byte, len(msg)*2+1) + encoded := make([]byte, len(msg)*2) hex.Encode(encoded, msg) conn.Write(append(encoded, '\n')) } From 5e526af47bcd7ee3e8879086f69593a9bbdcc814 Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Mon, 10 Aug 2015 20:26:37 +0300 Subject: [PATCH 5/5] Set version dynamically via ldflags --- Makefile | 4 ++-- settings.go | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d951930..0e39f2d 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,10 @@ SOURCE_PATH = /gopath/src/github.com/buger/gor/ release: release-x86 release-x64 release-x64: - docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 --env CGO_ENABLED=0 -i gor go build && tar -czf gor_x64.tar.gz gor && rm gor + docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 --env CGO_ENABLED=0 -i gor go build -ldflags "-X main.VERSION $(VERSION)"&& tar -czf gor_$(VERSION)_x64.tar.gz gor && rm gor release-x86: - docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=386 --env CGO_ENABLED=0 -i gor go build && tar -czf gor_x86.tar.gz gor && rm gor + docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=386 --env CGO_ENABLED=0 -i gor go build -ldflags "-X main.VERSION $(VERSION)" && tar -czf gor_$(VERSION)_x86.tar.gz gor && rm gor dbuild: docker build -t gor . diff --git a/settings.go b/settings.go index 3356797..d74a4f6 100644 --- a/settings.go +++ b/settings.go @@ -7,10 +7,7 @@ import ( "os" ) -const ( - // VERSION specifies Gor current version - VERSION = "0.9.8" -) +var VERSION string // MultiOption allows to specify multiple flags with same name and collects all values into array type MultiOption []string