-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
54 lines (47 loc) · 1.05 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
package cf_forbidden
import (
"github.com/Danny-Dasilva/CycleTLS/cycletls"
"net/http"
)
type M map[string]string
type Client struct {
tls cycletls.CycleTLS
Headers M
Ja3 string
UserAgent string
}
func New() (*Client, error) {
client := &Client{
tls: cycletls.Init(),
}
return client, nil
}
func (c Client) Do(url string, opt cycletls.Options, method string) (cycletls.Response, error) {
for k, v := range c.Headers {
opt.Headers[k] = v
}
if opt.Ja3 == "" {
opt.Ja3 = c.Ja3
}
if opt.UserAgent == "" {
opt.UserAgent = c.UserAgent
}
return c.tls.Do(url, opt, method)
}
func (c Client) Get(url string, headers M) (cycletls.Response, error) {
opt := cycletls.Options{
Headers: headers,
Ja3: c.Ja3,
UserAgent: c.UserAgent,
}
return c.Do(url, opt, http.MethodGet)
}
func (c Client) Post(url string, headers M, body string) (cycletls.Response, error) {
options := cycletls.Options{
Headers: headers,
Ja3: c.Ja3,
UserAgent: c.UserAgent,
Body: body,
}
return c.Do(url, options, http.MethodPost)
}