fix requestV1 requestV1 error
This commit is contained in:
parent
0b35c2ca09
commit
d2eb26d4ac
@ -2,6 +2,7 @@ package flaresolverr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@ -43,36 +44,45 @@ func (f *Flaresolverr) requestV1(req *V1RequestBase) (*V1ResponseBase, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode() != 200 {
|
||||
return nil, fmt.Errorf("request failed: status code: %v", resp.StatusCode())
|
||||
}
|
||||
var res V1ResponseBase
|
||||
err = json.Unmarshal(resp.Body(), &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.Solution != nil && res.Solution.RawCookies != nil {
|
||||
for _, cookie := range res.Solution.RawCookies {
|
||||
sec := int64(cookie.Expires)
|
||||
nsec := int64((cookie.Expires - float64(sec)) * 1e9)
|
||||
res.Solution.Cookies = append(res.Solution.Cookies, &http.Cookie{
|
||||
Name: cookie.Name,
|
||||
Value: cookie.Value,
|
||||
Expires: time.Unix(sec, nsec),
|
||||
Domain: cookie.Domain,
|
||||
Path: cookie.Path,
|
||||
Secure: cookie.Secure,
|
||||
HttpOnly: cookie.HttpOnly,
|
||||
})
|
||||
if res.Solution != nil {
|
||||
if res.Solution.RawCookies != nil {
|
||||
for _, cookie := range res.Solution.RawCookies {
|
||||
sec := int64(cookie.Expires)
|
||||
nsec := int64((cookie.Expires - float64(sec)) * 1e9)
|
||||
res.Solution.Cookies = append(res.Solution.Cookies, &http.Cookie{
|
||||
Name: cookie.Name,
|
||||
Value: cookie.Value,
|
||||
Expires: time.Unix(sec, nsec),
|
||||
Domain: cookie.Domain,
|
||||
Path: cookie.Path,
|
||||
Secure: cookie.Secure,
|
||||
HttpOnly: cookie.HttpOnly,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if res.Solution.RawResponse != nil {
|
||||
switch v := res.Solution.RawResponse.(type) {
|
||||
case string:
|
||||
res.Solution.Response = res.Solution.RawResponse.(string)
|
||||
case map[string]any:
|
||||
jsonBytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.Solution.Response = string(jsonBytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
switch v := res.Solution.RawResponse.(type) {
|
||||
case string:
|
||||
res.Solution.Response = res.Solution.RawResponse.(string)
|
||||
case map[string]any:
|
||||
jsonBytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.Solution.Response = string(jsonBytes)
|
||||
}
|
||||
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user