From 082ff6d0293a3a865911884ae4ff506ea75eeb90 Mon Sep 17 00:00:00 2001 From: xenolf Date: Thu, 21 Jul 2016 03:24:11 +0200 Subject: [PATCH] Removed HTTPTimeout and exported a new HTTPClient variable as a replacement. The HTTPTimeout was not honored by the default client. Clients should now construct their own HTTPClient for overriding the timeout. Fixes #246 --- acme/http.go | 14 +++++--------- cli_handlers.go | 3 ++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/acme/http.go b/acme/http.go index 3b5a37cb..99d452e9 100644 --- a/acme/http.go +++ b/acme/http.go @@ -8,17 +8,13 @@ import ( "net/http" "runtime" "strings" - "time" ) // UserAgent (if non-empty) will be tacked onto the User-Agent string in requests. var UserAgent string -// HTTPTimeout is used to override the default HTTP timeout of 10 seconds. -var HTTPTimeout = 10 * time.Second - -// defaultClient is an HTTP client with a reasonable timeout value. -var defaultClient = http.Client{Timeout: HTTPTimeout} +// HTTPClient is an HTTP client with a reasonable timeout value. +var HTTPClient = http.Client{Timeout: 10} const ( // defaultGoUserAgent is the Go HTTP package user agent string. Too @@ -39,7 +35,7 @@ func httpHead(url string) (resp *http.Response, err error) { req.Header.Set("User-Agent", userAgent()) - resp, err = defaultClient.Do(req) + resp, err = HTTPClient.Do(req) if err != nil { return resp, err } @@ -57,7 +53,7 @@ func httpPost(url string, bodyType string, body io.Reader) (resp *http.Response, req.Header.Set("Content-Type", bodyType) req.Header.Set("User-Agent", userAgent()) - return defaultClient.Do(req) + return HTTPClient.Do(req) } // httpGet performs a GET request with a proper User-Agent string. @@ -69,7 +65,7 @@ func httpGet(url string) (resp *http.Response, err error) { } req.Header.Set("User-Agent", userAgent()) - return defaultClient.Do(req) + return HTTPClient.Do(req) } // getJSON performs an HTTP GET request and parses the response body diff --git a/cli_handlers.go b/cli_handlers.go index 59d524a5..8425f337 100644 --- a/cli_handlers.go +++ b/cli_handlers.go @@ -7,6 +7,7 @@ import ( "encoding/json" "encoding/pem" "io/ioutil" + "net/http" "os" "path" "strings" @@ -39,7 +40,7 @@ func checkFolder(path string) error { func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) { if c.GlobalIsSet("http-timeout") { - acme.HTTPTimeout = time.Duration(c.GlobalInt("http-timeout")) * time.Second + acme.HTTPClient = http.Client{Timeout: time.Duration(c.GlobalInt("http-timeout")) * time.Second} } if c.GlobalIsSet("dns-timeout") {