forked from Danny-Dasilva/CycleTLS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
63 lines (55 loc) · 1.48 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
58
59
60
61
62
63
package cycletls
import (
"time"
http "github.com/pixelbender/CycleTLS/cycletls/fhttp"
"golang.org/x/net/proxy"
)
type browser struct {
// Return a greeting that embeds the name in a message.
JA3 string
UserAgent string
Cookies []Cookie
}
var disabledRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
func clientBuilder(browser browser, dialer proxy.ContextDialer, timeout int, disableRedirect bool) http.Client {
//if timeout is not set in call default to 15
if timeout == 0 {
timeout = 15
}
client := http.Client{
Transport: newRoundTripper(browser, dialer),
Timeout: time.Duration(timeout) * time.Second,
}
//if disableRedirect is set to true httpclient will not redirect
if disableRedirect {
client.CheckRedirect = disabledRedirect
}
return client
}
// newClient creates a new http client
func newClient(browser browser, timeout int, disableRedirect bool, UserAgent string, proxyURL ...string) (http.Client, error) {
//fix check PR
if len(proxyURL) > 0 && len(proxyURL[0]) > 0 {
dialer, err := newConnectDialer(proxyURL[0], UserAgent)
if err != nil {
return http.Client{
Timeout: time.Duration(timeout) * time.Second,
CheckRedirect: disabledRedirect, //fix this fallthrough issue (test for incorrect proxy)
}, err
}
return clientBuilder(
browser,
dialer,
timeout,
disableRedirect,
), nil
}
return clientBuilder(
browser,
proxy.Direct,
timeout,
disableRedirect,
), nil
}