forked from delivey/cclient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
57 lines (52 loc) · 1.45 KB
/
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
48
49
50
51
52
53
54
55
56
57
package cclient
import (
"time"
http "github.com/Carcraftz/fhttp"
"golang.org/x/net/proxy"
utls "github.com/Carcraftz/utls"
)
func NewClient(clientHello utls.ClientHelloID, proxyUrl string, allowRedirect bool, timeout time.Duration) (http.Client, error) {
if len(proxyUrl) > 0 {
dialer, err := newConnectDialer(proxyUrl)
if err != nil {
if allowRedirect {
return http.Client{
Timeout: time.Second * timeout,
}, err
}
return http.Client{
Timeout: time.Second * timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}, err
}
if allowRedirect {
return http.Client{
Transport: newRoundTripper(clientHello, dialer),
Timeout: time.Second * timeout,
}, nil
}
return http.Client{
Transport: newRoundTripper(clientHello, dialer),
Timeout: time.Second * timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}, nil
} else {
if allowRedirect {
return http.Client{
Transport: newRoundTripper(clientHello, proxy.Direct),
Timeout: time.Second * timeout,
}, nil
}
return http.Client{
Transport: newRoundTripper(clientHello, proxy.Direct),
Timeout: time.Second * timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}, nil
}
}