forked from TrueCloudLab/lego
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
This commit is contained in:
parent
58ead76066
commit
082ff6d029
2 changed files with 7 additions and 10 deletions
14
acme/http.go
14
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
|
||||
|
|
|
@ -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") {
|
||||
|
|
Loading…
Reference in a new issue