Aioweb migration #1

Merged
TPV merged 5 commits from aioweb-migration into main 2026-07-19 01:26:35 +00:00
Showing only changes of commit d307be60b0 - Show all commits
+12 -2
View File
@@ -15,16 +15,26 @@ from aioweb_tls import CurlCffi, TLSSession
from monitor_utils.constants import CLIENT_IDENTIFIERS, RETRY_LIMIT
def get_default_session(proxies: AioProxies) -> TLSSession:
def get_default_session(
proxies: AioProxies, headers: dict | None = None
) -> TLSSession:
"""Return a TLSSession impersonating a random client fingerprint.
Fingerprint rotation lives here so every monitor rotates the same way; the
caller owns the session lifetime via ``async with``.
Cookies are not set here: aioweb has no constructor cookie path, and
monitors usually obtain them at runtime, so call session.set_cookie(name,
value, domain=...) where they are fetched (e.g. a pre_task_func) instead.
Args:
proxies: Pool attached to the session as proxy_pool, which send_request
rotates through per request. Required so a session can never send
un-proxied.
headers: Default headers merged into every request by aioweb. Use for
monitor-wide static headers; per-request headers still go through
send_request. The curl_cffi impersonation already supplies a
matching User-Agent, so one is not defaulted here.
Returns:
A TLSSession over a curl_cffi backend with a random impersonation, with
@@ -32,7 +42,7 @@ def get_default_session(proxies: AioProxies) -> TLSSession:
"""
impersonate = random.choice(CLIENT_IDENTIFIERS)
session = TLSSession(backend=CurlCffi(impersonate=impersonate))
session = TLSSession(backend=CurlCffi(impersonate=impersonate), headers=headers)
session.proxy_pool = proxies
return session