refactor: Improve parameter naming for clarity in URL arguments
This commit is contained in:
@@ -20,14 +20,14 @@ func NewCycletlsClient(ja3, userAgent string) *cycletlsClient {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cycletlsClient) Get(URL string, opts *cycletls.Options) (cycletls.Response, error) {
|
||||
func (c *cycletlsClient) Get(reqURL string, opts *cycletls.Options) (cycletls.Response, error) {
|
||||
opts.Ja3 = c.ja3
|
||||
opts.UserAgent = c.userAgent
|
||||
return c.client.Do(URL, *opts, http.MethodGet)
|
||||
return c.client.Do(reqURL, *opts, http.MethodGet)
|
||||
}
|
||||
|
||||
func (c *cycletlsClient) Post(URL string, opts *cycletls.Options) (cycletls.Response, error) {
|
||||
func (c *cycletlsClient) Post(reqURL string, opts *cycletls.Options) (cycletls.Response, error) {
|
||||
opts.Ja3 = c.ja3
|
||||
opts.UserAgent = c.userAgent
|
||||
return c.client.Do(URL, *opts, http.MethodPost)
|
||||
return c.client.Do(reqURL, *opts, http.MethodPost)
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ type Flaresolverr struct {
|
||||
proxy string
|
||||
}
|
||||
|
||||
func GetInstance(URL string, sessionID string, proxy string) (*Flaresolverr, error) {
|
||||
if instance, ok := instances[URL]; ok {
|
||||
func GetInstance(flaresolverrURL string, sessionID string, proxy string) (*Flaresolverr, error) {
|
||||
if instance, ok := instances[flaresolverrURL]; ok {
|
||||
return instance, nil
|
||||
}
|
||||
flareSolverr := &Flaresolverr{
|
||||
url: URL,
|
||||
v1Url: strings.TrimSuffix(URL, "/") + "/v1",
|
||||
url: flaresolverrURL,
|
||||
v1Url: strings.TrimSuffix(flaresolverrURL, "/") + "/v1",
|
||||
sessionID: sessionID,
|
||||
proxy: proxy,
|
||||
}
|
||||
instances[URL] = flareSolverr
|
||||
instances[flaresolverrURL] = flareSolverr
|
||||
return flareSolverr, nil
|
||||
}
|
||||
|
||||
@@ -82,27 +82,27 @@ func (f *Flaresolverr) requestV1(req *V1RequestBase) (*V1ResponseBase, error) {
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) GetV1(URL string, req *V1RequestBase) (*V1ResponseBase, error) {
|
||||
func (f *Flaresolverr) GetV1(reqURL string, req *V1RequestBase) (*V1ResponseBase, error) {
|
||||
if req == nil {
|
||||
req = &V1RequestBase{
|
||||
MaxTimeout: 60000, // 60 秒
|
||||
}
|
||||
}
|
||||
req.Cmd = "request.get"
|
||||
req.URL = URL
|
||||
req.URL = reqURL
|
||||
req.Session = f.sessionID
|
||||
|
||||
return f.requestV1(req)
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) PostV1(URL string, req *V1RequestBase) (*V1ResponseBase, error) {
|
||||
func (f *Flaresolverr) PostV1(reqURL string, req *V1RequestBase) (*V1ResponseBase, error) {
|
||||
if req == nil {
|
||||
req = &V1RequestBase{
|
||||
MaxTimeout: 60000, // 60 秒
|
||||
}
|
||||
}
|
||||
req.Cmd = "request.post"
|
||||
req.URL = URL
|
||||
req.URL = reqURL
|
||||
req.Session = f.sessionID
|
||||
|
||||
return f.requestV1(req)
|
||||
@@ -157,6 +157,12 @@ func (f *Flaresolverr) preSimulateRequest(opts *SimulateOptions) error {
|
||||
}
|
||||
f.cycletlsC = NewCycletlsClient(ja3, ua)
|
||||
}
|
||||
if opts == nil {
|
||||
opts = &SimulateOptions{}
|
||||
}
|
||||
if opts.HttpCookies == nil {
|
||||
opts.HttpCookies = []*http.Cookie{}
|
||||
}
|
||||
opts.Cookies = ConvertToCycletlsCookies(opts.HttpCookies)
|
||||
if f.proxy != "" {
|
||||
opts.Proxy = f.proxy
|
||||
@@ -164,26 +170,30 @@ func (f *Flaresolverr) preSimulateRequest(opts *SimulateOptions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) SimulateGet(URL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
func (f *Flaresolverr) SimulateGet(reqURL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
if opts == nil {
|
||||
opts = &SimulateOptions{}
|
||||
}
|
||||
err := f.preSimulateRequest(opts)
|
||||
if err != nil {
|
||||
return cycletls.Response{}, err
|
||||
}
|
||||
|
||||
return f.cycletlsC.Get(URL, opts.Options)
|
||||
return f.cycletlsC.Get(reqURL, &opts.Options)
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) SimulatePost(URL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
func (f *Flaresolverr) SimulatePost(reqURL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
if opts == nil {
|
||||
opts = &SimulateOptions{}
|
||||
}
|
||||
err := f.preSimulateRequest(opts)
|
||||
if err != nil {
|
||||
return cycletls.Response{}, err
|
||||
}
|
||||
|
||||
return f.cycletlsC.Post(URL, opts.Options)
|
||||
return f.cycletlsC.Post(reqURL, &opts.Options)
|
||||
}
|
||||
|
||||
type SimulateOptions struct {
|
||||
*cycletls.Options
|
||||
cycletls.Options
|
||||
HttpCookies []*http.Cookie
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestImitateGet(t *testing.T) {
|
||||
cookies := resp.Solution.Cookies
|
||||
resp1, err := f.SimulateGet("https://nopecha.com/demo/cloudflare", &flaresolverr.SimulateOptions{
|
||||
HttpCookies: cookies,
|
||||
Options: &cycletls.Options{
|
||||
Options: cycletls.Options{
|
||||
ForceHTTP3: true,
|
||||
},
|
||||
}) // ImitateGet uses cookies to simulate browser requests and also simulates the browser's ja3 fingerprint.
|
||||
|
||||
Reference in New Issue
Block a user