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"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserAgent (if non-empty) will be tacked onto the User-Agent string in requests.
|
// UserAgent (if non-empty) will be tacked onto the User-Agent string in requests.
|
||||||
var UserAgent string
|
var UserAgent string
|
||||||
|
|
||||||
// HTTPTimeout is used to override the default HTTP timeout of 10 seconds.
|
// HTTPClient is an HTTP client with a reasonable timeout value.
|
||||||
var HTTPTimeout = 10 * time.Second
|
var HTTPClient = http.Client{Timeout: 10}
|
||||||
|
|
||||||
// defaultClient is an HTTP client with a reasonable timeout value.
|
|
||||||
var defaultClient = http.Client{Timeout: HTTPTimeout}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// defaultGoUserAgent is the Go HTTP package user agent string. Too
|
// 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())
|
req.Header.Set("User-Agent", userAgent())
|
||||||
|
|
||||||
resp, err = defaultClient.Do(req)
|
resp, err = HTTPClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, err
|
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("Content-Type", bodyType)
|
||||||
req.Header.Set("User-Agent", userAgent())
|
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.
|
// 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())
|
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
|
// getJSON performs an HTTP GET request and parses the response body
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -39,7 +40,7 @@ func checkFolder(path string) error {
|
||||||
func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) {
|
func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) {
|
||||||
|
|
||||||
if c.GlobalIsSet("http-timeout") {
|
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") {
|
if c.GlobalIsSet("dns-timeout") {
|
||||||
|
|
Loading…
Reference in a new issue