Lazy initialization Flaresolverr.cycletlsC
This commit is contained in:
parent
d2eb26d4ac
commit
fd3b5ce79e
@ -30,11 +30,6 @@ func GetInstance(URL string, sessionID string, proxy string) (*Flaresolverr, err
|
||||
sessionID: sessionID,
|
||||
proxy: proxy,
|
||||
}
|
||||
ua, ja3, err := flareSolverr.GetJa3AndUserAgent()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flareSolverr.cycletlsC = NewCycletlsClient(ja3, ua)
|
||||
instances[URL] = flareSolverr
|
||||
return flareSolverr, nil
|
||||
}
|
||||
@ -144,19 +139,36 @@ func (f *Flaresolverr) GetJa3AndUserAgent() (ua string, ja3 string, err error) {
|
||||
return resp.Solution.UserAgent, resp.Solution.RawResponse.(map[string]any)["tls"].(map[string]any)["ja3"].(string), nil
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) SimulateGet(URL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
func (f *Flaresolverr) preSimulateRequest(opts *SimulateOptions) error {
|
||||
if f.cycletlsC == nil {
|
||||
ua, ja3, err := f.GetJa3AndUserAgent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.cycletlsC = NewCycletlsClient(ja3, ua)
|
||||
}
|
||||
opts.Cookies = ConvertToCycletlsCookies(opts.HttpCookies)
|
||||
if f.proxy != "" {
|
||||
opts.Proxy = f.proxy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) SimulateGet(URL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
err := f.preSimulateRequest(opts)
|
||||
if err != nil {
|
||||
return cycletls.Response{}, err
|
||||
}
|
||||
|
||||
return f.cycletlsC.Get(URL, &opts.Options)
|
||||
}
|
||||
|
||||
func (f *Flaresolverr) SimulatePost(URL string, opts *SimulateOptions) (cycletls.Response, error) {
|
||||
opts.Cookies = ConvertToCycletlsCookies(opts.HttpCookies)
|
||||
if f.proxy != "" {
|
||||
opts.Proxy = f.proxy
|
||||
err := f.preSimulateRequest(opts)
|
||||
if err != nil {
|
||||
return cycletls.Response{}, err
|
||||
}
|
||||
|
||||
return f.cycletlsC.Post(URL, &opts.Options)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user