mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 12:35:30 +00:00

* Add support for sessions * Add tests for sessions * Missing return type * Don't re-create an existing session * Return success in case of session doesn't exists on destroy * Create session if necessary on get request * Add session TTL to the request.get method When fetching some webpage with a predefined session id, FlareSorverr is using existing instance of WebDriver. That allows user to not manage cookies explicitly and rely on WebDriver to maintain the session. However, if session has been created long time ago, CloudFlare might stop accepting the requests, so we want to recreate the session time to time. From the user perspective the easiest way of doing it is to define their expectation on the session duration. These changes add an option to define Time-to-live (TTL) for the session and FlareSorverr takes care about rotating the sessions. * Update message for session destroy in tests --------- Co-authored-by: Michel Roux <xefir@crystalyx.net>
85 lines
1.9 KiB
Python
85 lines
1.9 KiB
Python
|
|
STATUS_OK = "ok"
|
|
STATUS_ERROR = "error"
|
|
|
|
|
|
class ChallengeResolutionResultT:
|
|
url: str = None
|
|
status: int = None
|
|
headers: list = None
|
|
response: str = None
|
|
cookies: list = None
|
|
userAgent: str = None
|
|
|
|
def __init__(self, _dict):
|
|
self.__dict__.update(_dict)
|
|
|
|
|
|
class ChallengeResolutionT:
|
|
status: str = None
|
|
message: str = None
|
|
result: ChallengeResolutionResultT = None
|
|
|
|
def __init__(self, _dict):
|
|
self.__dict__.update(_dict)
|
|
if self.result is not None:
|
|
self.result = ChallengeResolutionResultT(self.result)
|
|
|
|
|
|
class V1RequestBase(object):
|
|
# V1RequestBase
|
|
cmd: str = None
|
|
cookies: list = None
|
|
maxTimeout: int = None
|
|
proxy: dict = None
|
|
session: str = None
|
|
session_ttl_minutes: int = None
|
|
headers: list = None # deprecated v2.0.0, not used
|
|
userAgent: str = None # deprecated v2.0.0, not used
|
|
|
|
# V1Request
|
|
url: str = None
|
|
postData: str = None
|
|
returnOnlyCookies: bool = None
|
|
download: bool = None # deprecated v2.0.0, not used
|
|
returnRawHtml: bool = None # deprecated v2.0.0, not used
|
|
|
|
def __init__(self, _dict):
|
|
self.__dict__.update(_dict)
|
|
|
|
|
|
class V1ResponseBase(object):
|
|
# V1ResponseBase
|
|
status: str = None
|
|
message: str = None
|
|
startTimestamp: int = None
|
|
endTimestamp: int = None
|
|
version: str = None
|
|
|
|
# V1ResponseSolution
|
|
solution: ChallengeResolutionResultT = None
|
|
|
|
# hidden vars
|
|
__error_500__: bool = False
|
|
|
|
def __init__(self, _dict):
|
|
self.__dict__.update(_dict)
|
|
if self.solution is not None:
|
|
self.solution = ChallengeResolutionResultT(self.solution)
|
|
|
|
|
|
class IndexResponse(object):
|
|
msg: str = None
|
|
version: str = None
|
|
userAgent: str = None
|
|
|
|
def __init__(self, _dict):
|
|
self.__dict__.update(_dict)
|
|
|
|
|
|
class HealthResponse(object):
|
|
status: str = None
|
|
|
|
def __init__(self, _dict):
|
|
self.__dict__.update(_dict)
|