tech: avoid using http.DefaultClient

This commit is contained in:
bergquist
2017-02-24 17:22:12 +01:00
parent 03354bc49a
commit 05952688c5
2 changed files with 29 additions and 2 deletions
+15 -1
View File
@@ -4,9 +4,11 @@ import (
"bytes"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"path"
"time"
"github.com/grafana/grafana/pkg/util"
)
@@ -17,6 +19,18 @@ type WebdavUploader struct {
password string
}
var netTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 60 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
}
var netClient = &http.Client{
Timeout: time.Second * 60,
Transport: netTransport,
}
func (u *WebdavUploader) Upload(pa string) (string, error) {
url, _ := url.Parse(u.url)
url.Path = path.Join(url.Path, util.GetRandomString(20)+".png")
@@ -28,7 +42,7 @@ func (u *WebdavUploader) Upload(pa string) (string, error) {
req.SetBasicAuth(u.username, u.password)
}
res, err := http.DefaultClient.Do(req)
res, err := netClient.Do(req)
if err != nil {
return "", err