forked from TrueCloudLab/lego
Make DO and namecheap providers use a HTTP client with a timeout.
This commit is contained in:
parent
0ba8d6993b
commit
e06278fead
2 changed files with 10 additions and 6 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xenolf/lego/acme"
|
||||
)
|
||||
|
@ -64,7 +65,8 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", d.apiAuthToken))
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
client := http.Client{Timeout: 30 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -109,7 +111,8 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", d.apiAuthToken))
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
client := http.Client{Timeout: 30 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ var (
|
|||
debug = false
|
||||
defaultBaseURL = "https://api.namecheap.com/xml.response"
|
||||
getIpURL = "https://dynamicdns.park-your-domain.com/getip"
|
||||
httpClient = http.Client{Timeout: 60 * time.Second}
|
||||
)
|
||||
|
||||
// DNSProvider is an implementation of the ChallengeProviderTimeout interface
|
||||
|
@ -93,7 +94,7 @@ type apierror struct {
|
|||
// getClientIP returns the client's public IP address. It uses namecheap's
|
||||
// IP discovery service to perform the lookup.
|
||||
func getClientIP() (addr string, err error) {
|
||||
resp, err := http.Get(getIpURL)
|
||||
resp, err := httpClient.Get(getIpURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -179,7 +180,7 @@ func (d *DNSProvider) getTLDs() (tlds map[string]string, err error) {
|
|||
reqURL, _ := url.Parse(d.baseURL)
|
||||
reqURL.RawQuery = values.Encode()
|
||||
|
||||
resp, err := http.Get(reqURL.String())
|
||||
resp, err := httpClient.Get(reqURL.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -228,7 +229,7 @@ func (d *DNSProvider) getHosts(ch *challenge) (hosts []host, err error) {
|
|||
reqURL, _ := url.Parse(d.baseURL)
|
||||
reqURL.RawQuery = values.Encode()
|
||||
|
||||
resp, err := http.Get(reqURL.String())
|
||||
resp, err := httpClient.Get(reqURL.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -278,7 +279,7 @@ func (d *DNSProvider) setHosts(ch *challenge, hosts []host) error {
|
|||
values.Add("TTL"+ind, h.TTL)
|
||||
}
|
||||
|
||||
resp, err := http.PostForm(d.baseURL, values)
|
||||
resp, err := httpClient.PostForm(d.baseURL, values)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue