-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
49 lines (44 loc) · 1.19 KB
/
utils.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
48
49
package zb
import (
"net"
"net/http"
"net/url"
"time"
)
var (
DefaultTransport *http.Transport
)
func init() {
DefaultTransport = &http.Transport{
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
IdleConnTimeout: 1 * time.Minute,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
DisableKeepAlives: false,
MaxResponseHeaderBytes: 1 << 15,
}
}
func CloneDefaultTransport() *http.Transport {
return &http.Transport{DialContext: DefaultTransport.DialContext,
IdleConnTimeout: DefaultTransport.IdleConnTimeout,
TLSHandshakeTimeout: DefaultTransport.TLSHandshakeTimeout,
ExpectContinueTimeout: DefaultTransport.ExpectContinueTimeout,
MaxResponseHeaderBytes: DefaultTransport.MaxResponseHeaderBytes,
Proxy: DefaultTransport.Proxy,
DisableKeepAlives: DefaultTransport.DisableKeepAlives,
}
}
// "socks5://127.0.0.1:1080"
func ParseProxy(proxyURL string) (res func(*http.Request) (*url.URL, error), err error) {
var purl *url.URL
purl, err = url.Parse(proxyURL)
if err != nil {
return
}
res = http.ProxyURL(purl)
return
}