mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech: avoid using http.DefaultClient
This commit is contained in:
parent
03354bc49a
commit
05952688c5
@ -4,9 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
@ -17,6 +19,18 @@ type WebdavUploader struct {
|
|||||||
password string
|
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) {
|
func (u *WebdavUploader) Upload(pa string) (string, error) {
|
||||||
url, _ := url.Parse(u.url)
|
url, _ := url.Parse(u.url)
|
||||||
url.Path = path.Join(url.Path, util.GetRandomString(20)+".png")
|
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)
|
req.SetBasicAuth(u.username, u.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := http.DefaultClient.Do(req)
|
res, err := netClient.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -5,7 +5,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context/ctxhttp"
|
"golang.org/x/net/context/ctxhttp"
|
||||||
|
|
||||||
@ -22,6 +24,17 @@ type Webhook struct {
|
|||||||
HttpHeader map[string]string
|
HttpHeader map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var netTransport = &http.Transport{
|
||||||
|
Dial: (&net.Dialer{
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
}).Dial,
|
||||||
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
var netClient = &http.Client{
|
||||||
|
Timeout: time.Second * 30,
|
||||||
|
Transport: netTransport,
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
webhookQueue chan *Webhook
|
webhookQueue chan *Webhook
|
||||||
webhookLog log.Logger
|
webhookLog log.Logger
|
||||||
@ -68,7 +81,7 @@ func sendWebRequestSync(ctx context.Context, webhook *Webhook) error {
|
|||||||
request.Header.Set(k, v)
|
request.Header.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := ctxhttp.Do(ctx, http.DefaultClient, request)
|
resp, err := ctxhttp.Do(ctx, netClient, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user