added passing headers

This commit is contained in:
TPV committed 2026-07-30 14:29:58 -07:00
1 parent 8903be2685
commit 2e6e7ebc69
2 files changed
+18 -4

No files matched your search

+3 -1
View File
@@ -344,6 +344,7 @@ async def run_bounded_cycle(
proxies: AioProxies,
collection: AsyncIOMotorCollection,
*,
headers: dict | None = None,
session_timeout: int = TIMEOUT_SECONDS,
max_clients: int = MAX_CURL_HANDLES,
cycle_timeout: int = CYCLE_TIMEOUT_SECONDS,
@@ -369,6 +370,7 @@ async def run_bounded_cycle(
task_func: Awaitable invoked per category.
proxies: Pool bound to each cycle's fresh session.
collection: Mongo collection forwarded to every callback.
headers: Monitor-wide static headers merged into every request.
session_timeout: Per-request timeout on the cycle's session.
max_clients: Curl handle pool size. Keep at or above the monitor's
whole fan-out; see get_default_session for why.
@@ -382,7 +384,7 @@ async def run_bounded_cycle(
"""
async with get_default_session(
proxies, timeout=session_timeout, max_clients=max_clients
proxies, headers, timeout=session_timeout, max_clients=max_clients
) as session:
try:
async with asyncio.timeout(cycle_timeout):
+15 -3
View File
@@ -35,10 +35,15 @@ def stub_session(monkeypatch) -> dict:
"""Fake get_default_session, recording each call's kwargs and session."""
calls = []
def fake(proxies, timeout=None, max_clients=None):
def fake(proxies, headers=None, timeout=None, max_clients=None):
session = FakeSession()
calls.append(
{"timeout": timeout, "max_clients": max_clients, "session": session}
{
"headers": headers,
"timeout": timeout,
"max_clients": max_clients,
"session": session,
}
)
return session
@@ -66,10 +71,17 @@ def test_session_params_reach_the_factory(monkeypatch):
asyncio.run(
run_bounded_cycle(
["a"], task, None, None, session_timeout=8, max_clients=81
["a"],
task,
None,
None,
headers={"referer": "https://x/"},
session_timeout=8,
max_clients=81,
)
)
assert calls[0]["headers"] == {"referer": "https://x/"}
assert calls[0]["timeout"] == 8
assert calls[0]["max_clients"] == 81