added passing headers
This commit is contained in:
1 parent
8903be2685
commit
2e6e7ebc69
2 files changed
+18
-4
No files matched your search
@@ -344,6 +344,7 @@ async def run_bounded_cycle(
|
|||||||
proxies: AioProxies,
|
proxies: AioProxies,
|
||||||
collection: AsyncIOMotorCollection,
|
collection: AsyncIOMotorCollection,
|
||||||
*,
|
*,
|
||||||
|
headers: dict | None = None,
|
||||||
session_timeout: int = TIMEOUT_SECONDS,
|
session_timeout: int = TIMEOUT_SECONDS,
|
||||||
max_clients: int = MAX_CURL_HANDLES,
|
max_clients: int = MAX_CURL_HANDLES,
|
||||||
cycle_timeout: int = CYCLE_TIMEOUT_SECONDS,
|
cycle_timeout: int = CYCLE_TIMEOUT_SECONDS,
|
||||||
@@ -369,6 +370,7 @@ async def run_bounded_cycle(
|
|||||||
task_func: Awaitable invoked per category.
|
task_func: Awaitable invoked per category.
|
||||||
proxies: Pool bound to each cycle's fresh session.
|
proxies: Pool bound to each cycle's fresh session.
|
||||||
collection: Mongo collection forwarded to every callback.
|
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.
|
session_timeout: Per-request timeout on the cycle's session.
|
||||||
max_clients: Curl handle pool size. Keep at or above the monitor's
|
max_clients: Curl handle pool size. Keep at or above the monitor's
|
||||||
whole fan-out; see get_default_session for why.
|
whole fan-out; see get_default_session for why.
|
||||||
@@ -382,7 +384,7 @@ async def run_bounded_cycle(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
async with get_default_session(
|
async with get_default_session(
|
||||||
proxies, timeout=session_timeout, max_clients=max_clients
|
proxies, headers, timeout=session_timeout, max_clients=max_clients
|
||||||
) as session:
|
) as session:
|
||||||
try:
|
try:
|
||||||
async with asyncio.timeout(cycle_timeout):
|
async with asyncio.timeout(cycle_timeout):
|
||||||
|
|||||||
@@ -35,10 +35,15 @@ def stub_session(monkeypatch) -> dict:
|
|||||||
"""Fake get_default_session, recording each call's kwargs and session."""
|
"""Fake get_default_session, recording each call's kwargs and session."""
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
def fake(proxies, timeout=None, max_clients=None):
|
def fake(proxies, headers=None, timeout=None, max_clients=None):
|
||||||
session = FakeSession()
|
session = FakeSession()
|
||||||
calls.append(
|
calls.append(
|
||||||
{"timeout": timeout, "max_clients": max_clients, "session": session}
|
{
|
||||||
|
"headers": headers,
|
||||||
|
"timeout": timeout,
|
||||||
|
"max_clients": max_clients,
|
||||||
|
"session": session,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
return session
|
return session
|
||||||
|
|
||||||
@@ -66,10 +71,17 @@ def test_session_params_reach_the_factory(monkeypatch):
|
|||||||
|
|
||||||
asyncio.run(
|
asyncio.run(
|
||||||
run_bounded_cycle(
|
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]["timeout"] == 8
|
||||||
assert calls[0]["max_clients"] == 81
|
assert calls[0]["max_clients"] == 81
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user