Skip to content

Commit

Permalink
Option to configure timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Jul 31, 2015
1 parent 8f2e9bd commit 083c97a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type HTTPClientConfig struct {
FollowRedirects int
Debug bool
OriginalHost bool
Timeout time.Duration
}

type HTTPClient struct {
Expand All @@ -43,6 +44,10 @@ func NewHTTPClient(baseURL string, config *HTTPClientConfig) *HTTPClient {
u.Host += ":" + defaultPorts[u.Scheme]
}

if config.Timeout.Nanoseconds() == 0 {
config.Timeout = 5 * time.Second
}

client := new(HTTPClient)
client.baseURL = u.String()
client.host = u.Host
Expand Down Expand Up @@ -112,7 +117,7 @@ func (c *HTTPClient) Send(data []byte) (response []byte, err error) {
}
}

timeout := time.Now().Add(5 * time.Second)
timeout := time.Now().Add(c.config.Timeout)

c.conn.SetWriteDeadline(timeout)

Expand Down
2 changes: 2 additions & 0 deletions output_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type HTTPOutputConfig struct {

elasticSearch string

Timeout time.Duration
OriginalHost bool

Debug bool
Expand Down Expand Up @@ -97,6 +98,7 @@ func (o *HTTPOutput) startWorker() {
FollowRedirects: o.config.redirectLimit,
Debug: o.config.Debug,
OriginalHost: o.config.OriginalHost,
Timeout: o.config.Timeout,
})

deathCount := 0
Expand Down
1 change: 1 addition & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func init() {
flag.Var(&Settings.outputHTTP, "output-http", "Forwards incoming requests to given http address.\n\t# Redirect all incoming requests to staging.com address \n\tgor --input-raw :80 --output-http http://staging.com")
flag.IntVar(&Settings.outputHTTPConfig.workers, "output-http-workers", 0, "Gor uses dynamic worker scaling by default. Enter a number to run a set number of workers.")
flag.IntVar(&Settings.outputHTTPConfig.redirectLimit, "output-http-redirects", 0, "Enable how often redirects should be followed.")
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.")

Expand Down

0 comments on commit 083c97a

Please sign in to comment.