From 9f8d5e4076d5ef436b77b569a31d8fe47de420c1 Mon Sep 17 00:00:00 2001 From: "Andrew E. Bruno" Date: Fri, 18 Mar 2016 23:20:58 -0400 Subject: [PATCH] Add timeout to HTTP client --- providers/dns/dyn/dyn.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/providers/dns/dyn/dyn.go b/providers/dns/dyn/dyn.go index e13eb3c7..a16e68aa 100644 --- a/providers/dns/dyn/dyn.go +++ b/providers/dns/dyn/dyn.go @@ -7,6 +7,7 @@ import ( "fmt" "net/http" "strconv" + "time" "github.com/xenolf/lego/acme" ) @@ -64,7 +65,8 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) req.Header.Set("Auth-Token", d.token) } - resp, err := http.DefaultClient.Do(req) + client := &http.Client{Timeout: time.Duration(10 * time.Second)} + resp, err := client.Do(req) if err != nil { return nil, err } @@ -136,7 +138,9 @@ func (d *DNSProvider) logout() error { } req.Header.Set("Content-Type", "application/json") req.Header.Set("Auth-Token", d.token) - resp, err := http.DefaultClient.Do(req) + + client := &http.Client{Timeout: time.Duration(10 * time.Second)} + resp, err := client.Do(req) if err != nil { return err } @@ -219,7 +223,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { } req.Header.Set("Content-Type", "application/json") req.Header.Set("Auth-Token", d.token) - resp, err := http.DefaultClient.Do(req) + + client := &http.Client{Timeout: time.Duration(10 * time.Second)} + resp, err := client.Do(req) if err != nil { return err }