Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cycletls/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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 {
func clientBuilder(browser Browser, dialer proxy.ContextDialer, timeout int, disableRedirect bool, checkRedirect func(req *http.Request, via []*http.Request) error) http.Client {
//if timeout is not set in call default to 15
if timeout == 0 {
timeout = 15
Expand All @@ -33,6 +33,8 @@ func clientBuilder(browser Browser, dialer proxy.ContextDialer, timeout int, dis
//if disableRedirect is set to true httpclient will not redirect
if disableRedirect {
client.CheckRedirect = disabledRedirect
} else {
client.CheckRedirect = checkRedirect
}
return client
}
Expand Down Expand Up @@ -72,7 +74,7 @@ func NewTransportWithProxy(ja3 string, useragent string, proxy proxy.ContextDial
}

// newClient creates a new http client
func newClient(browser Browser, timeout int, disableRedirect bool, UserAgent string, proxyURL ...string) (http.Client, error) {
func newClient(browser Browser, timeout int, disableRedirect bool, UserAgent string, checkRedirect func(req *http.Request, via []*http.Request) error, proxyURL ...string) (http.Client, error) {
var dialer proxy.ContextDialer
if len(proxyURL) > 0 && len(proxyURL[0]) > 0 {
var err error
Expand All @@ -87,5 +89,5 @@ func newClient(browser Browser, timeout int, disableRedirect bool, UserAgent str
dialer = proxy.Direct
}

return clientBuilder(browser, dialer, timeout, disableRedirect), nil
return clientBuilder(browser, dialer, timeout, disableRedirect, checkRedirect), nil
}
44 changes: 23 additions & 21 deletions cycletls/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ import (

// Options sets CycleTLS client options
type Options struct {
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Ja3 string `json:"ja3"`
UserAgent string `json:"userAgent"`
Proxy string `json:"proxy"`
Cookies []Cookie `json:"cookies"`
Timeout int `json:"timeout"`
DisableRedirect bool `json:"disableRedirect"`
HeaderOrder []string `json:"headerOrder"`
OrderAsProvided bool `json:"orderAsProvided"` //TODO
InsecureSkipVerify bool `json:"insecureSkipVerify"`
ForceHTTP1 bool `json:"forceHTTP1"`
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Ja3 string `json:"ja3"`
UserAgent string `json:"userAgent"`
Proxy string `json:"proxy"`
Cookies []Cookie `json:"cookies"`
Timeout int `json:"timeout"`
DisableRedirect bool `json:"disableRedirect"`
CheckRedirect func(req *http.Request, via []*http.Request) error `json:"checkRedirect"`
HeaderOrder []string `json:"headerOrder"`
OrderAsProvided bool `json:"orderAsProvided"` //TODO
InsecureSkipVerify bool `json:"insecureSkipVerify"`
ForceHTTP1 bool `json:"forceHTTP1"`
}

type cycleTLSRequest struct {
Expand Down Expand Up @@ -85,6 +86,7 @@ func processRequest(request cycleTLSRequest) (result fullRequest) {
request.Options.Timeout,
request.Options.DisableRedirect,
request.Options.UserAgent,
request.Options.CheckRedirect,
request.Options.Proxy,
)
if err != nil {
Expand Down Expand Up @@ -241,14 +243,14 @@ func (client CycleTLS) Do(URL string, options Options, Method string) (response

options.URL = URL
options.Method = Method
// Set default values if not provided
if options.Ja3 == "" {
options.Ja3 = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,18-35-65281-45-17513-27-65037-16-10-11-5-13-0-43-23-51,29-23-24,0"
}
if options.UserAgent == "" {
// Set default values if not provided
if options.Ja3 == "" {
options.Ja3 = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,18-35-65281-45-17513-27-65037-16-10-11-5-13-0-43-23-51,29-23-24,0"
}
if options.UserAgent == "" {
// Mac OS Chrome 121
options.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
}
options.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
}
opt := cycleTLSRequest{"cycleTLSRequest", options}

res := processRequest(opt)
Expand Down