Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/client/client.go
310 views
1
package client
2
3
import (
4
http "github.com/Danny-Dasilva/fhttp"
5
6
"time"
7
8
"golang.org/x/net/proxy"
9
)
10
11
type Browser struct {
12
// Return a greeting that embeds the name in a message.
13
JA3 string
14
UserAgent string
15
Cookies []Cookie
16
}
17
18
var disabledRedirect = func(req *http.Request, via []*http.Request) error {
19
return http.ErrUseLastResponse
20
}
21
22
func clientBuilder(browser Browser, dialer proxy.ContextDialer, timeout int, disableRedirect bool) *http.Client {
23
//if timeout is not set in call default to 15
24
if timeout == 0 {
25
timeout = 15
26
}
27
client := &http.Client{
28
Transport: newRoundTripper(browser, dialer),
29
Timeout: time.Duration(timeout) * time.Second,
30
}
31
//if disableRedirect is set to true httpclient will not redirect
32
if disableRedirect {
33
client.CheckRedirect = disabledRedirect
34
}
35
return client
36
}
37
38
// newClient creates a new http client
39
func NewClient(browser Browser, timeout int, disableRedirect bool, UserAgent string, proxyURL ...string) (*http.Client, error) {
40
//fix check PR
41
if len(proxyURL) > 0 && len(proxyURL[0]) > 0 {
42
dialer, err := newConnectDialer(proxyURL[0], UserAgent)
43
if err != nil {
44
return &http.Client{
45
Timeout: time.Duration(timeout) * time.Second,
46
CheckRedirect: disabledRedirect, //fix this fallthrough issue (test for incorrect proxy)
47
}, err
48
}
49
return clientBuilder(
50
browser,
51
dialer,
52
timeout,
53
disableRedirect,
54
), nil
55
}
56
57
return clientBuilder(
58
browser,
59
proxy.Direct,
60
timeout,
61
disableRedirect,
62
), nil
63
64
}
65
66