减少http client初始化次数

This commit is contained in:
shadow1ng
2021-02-21 14:52:31 +08:00
parent 14c9847f88
commit 583e51d479
4 changed files with 24 additions and 11 deletions
+3 -3
View File
@@ -14,7 +14,7 @@ import (
)
var (
client *http.Client
Client *http.Client
clientNoRedirect *http.Client
dialTimout = 5 * time.Second
keepAlive = 15 * time.Second
@@ -44,7 +44,7 @@ func InitHttpClient(ThreadsNum int, DownProxy string, Timeout time.Duration) err
tr.Proxy = http.ProxyURL(u)
}
client = &http.Client{
Client = &http.Client{
Transport: tr,
Timeout: Timeout,
}
@@ -70,7 +70,7 @@ func DoRequest(req *http.Request, redirect bool) (*Response, error) {
var oResp *http.Response
var err error
if redirect {
oResp, err = client.Do(req)
oResp, err = Client.Do(req)
} else {
oResp, err = clientNoRedirect.Do(req)
}