-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
proxy.go
45 lines (40 loc) · 802 Bytes
/
proxy.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
// +build !go1.1 !go1.2
package request
import (
"net"
"net/http"
"net/url"
"time"
"golang.org/x/net/proxy"
)
func applyProxy(a *Args) (err error) {
if a.Proxy == "" {
return nil
}
u, err := url.Parse(a.Proxy)
if err != nil {
return err
}
switch u.Scheme {
case "http", "https":
a.Client.Transport = &http.Transport{
Proxy: http.ProxyURL(u),
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
case "socks5":
dialer, err := proxy.FromURL(u, proxy.Direct)
if err != nil {
return err
}
a.Client.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
}
return
}