🐛 Bug: 添加 HTTP 客户端会话上下文检查 (#2632)

This commit is contained in:
Ju4tCode 2024-04-08 20:17:03 +08:00 committed by GitHub
parent 7a232c7a4a
commit 9b4b1526b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View File

@ -124,6 +124,8 @@ class Session(HTTPClientSession):
@override
async def setup(self) -> None:
if self._client is not None:
raise RuntimeError("Session has already been initialized")
self._client = aiohttp.ClientSession(
cookies=self._cookies,
headers=self._headers,

View File

@ -93,6 +93,8 @@ class Session(HTTPClientSession):
@override
async def setup(self) -> None:
if self._client is not None:
raise RuntimeError("Session has already been initialized")
self._client = httpx.AsyncClient(
params=self._params,
headers=self._headers,

View File

@ -328,6 +328,11 @@ async def test_http_client_session(driver: Driver, server_url: URL):
with pytest.raises(RuntimeError):
await session.request(request)
with pytest.raises(RuntimeError): # noqa: PT012
async with session:
async with session:
...
async with session as session:
# simple post with query, headers, cookies and content
request = Request(