forked from x04/cclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
52 lines (41 loc) · 993 Bytes
/
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
package cclient
import (
"net/http"
"net/http/cookiejar"
"golang.org/x/net/proxy"
utls "github.com/refraction-networking/utls"
)
func NewClient(clientHello utls.ClientHelloID, enableJar bool, proxyUrl ...string) (http.Client, error) {
if len(proxyUrl) > 0 && len(proxyUrl) > 0 {
dialer, err := newConnectDialer(proxyUrl[0])
if err != nil {
return http.Client{}, err
}
if enableJar {
jar, err := cookiejar.New(nil)
if err != nil {
return http.Client{}, err
}
return http.Client{
Transport: newRoundTripper(clientHello, dialer),
Jar: jar,
}, nil
}
return http.Client{
Transport: newRoundTripper(clientHello, dialer),
}, nil
}
if enableJar {
jar, err := cookiejar.New(nil)
if err != nil {
return http.Client{}, err
}
return http.Client{
Transport: newRoundTripper(clientHello, proxy.Direct),
Jar: jar,
}, nil
}
return http.Client{
Transport: newRoundTripper(clientHello, proxy.Direct),
}, nil
}