-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_client.go
47 lines (41 loc) · 974 Bytes
/
http_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"net"
"net/http"
"net/url"
"time"
)
func initClient() {
// 配置使用的代理和dns
tran := http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
//优先使用Go内置DNS查询,替换DNS
Resolver: &net.Resolver{
PreferGo: true,
Dial: UserDNSDialer,
},
}).DialContext,
// MaxIdleConns: 20,
// IdleConnTimeout: 90 * time.Second,
// TLSHandshakeTimeout: 10 * time.Second,
// ExpectContinueTimeout: 1 * time.Second,
}
if config != nil && config.ProxyServer != "" {
url, err := url.Parse(config.ProxyServer)
if err != nil {
panic(err)
}
tran.Proxy = http.ProxyURL(url)
}
httpClient = &http.Client{
Transport: &tran,
//CheckRedirect: func(req *http.Request, via []*http.Request) error {
// log.Println(via, req)
// return http.ErrUseLastResponse
//},
}
}