mirror of
https://github.com/nonebot/nonebot2.git
synced 2026-04-20 16:25:42 +00:00
✨ support ping_interval and ping_timeout config
This commit is contained in:
@@ -324,6 +324,10 @@ class Mixin(HTTPClientMixin, WebSocketClientMixin):
|
||||
)
|
||||
)
|
||||
|
||||
autoping = True
|
||||
if setup.ping_interval is not UNSET:
|
||||
autoping = setup.ping_interval is not None
|
||||
|
||||
async with aiohttp.ClientSession(version=version, trust_env=True) as session:
|
||||
async with session.ws_connect(
|
||||
setup.url,
|
||||
@@ -331,6 +335,7 @@ class Mixin(HTTPClientMixin, WebSocketClientMixin):
|
||||
timeout=timeout,
|
||||
headers=setup.headers,
|
||||
proxy=setup.proxy,
|
||||
autoping=autoping,
|
||||
) as ws:
|
||||
yield WebSocket(request=setup, session=session, websocket=ws)
|
||||
|
||||
|
||||
@@ -83,7 +83,11 @@ class Mixin(WebSocketClientMixin):
|
||||
setup.timeout.connect or setup.timeout.read or setup.timeout.total
|
||||
)
|
||||
timeout_kwargs = exclude_unset(
|
||||
{"open_timeout": open_timeout, "close_timeout": setup.timeout.close}
|
||||
{
|
||||
"open_timeout": open_timeout,
|
||||
"close_timeout": setup.timeout.close,
|
||||
"ping_timeout": setup.timeout.ping,
|
||||
}
|
||||
)
|
||||
elif setup.timeout is not UNSET:
|
||||
timeout_kwargs = {
|
||||
@@ -102,11 +106,18 @@ class Mixin(WebSocketClientMixin):
|
||||
}
|
||||
)
|
||||
|
||||
kwargs = exclude_unset(
|
||||
{
|
||||
**timeout_kwargs,
|
||||
"ping_interval": setup.ping_interval,
|
||||
}
|
||||
)
|
||||
|
||||
connection = connect(
|
||||
str(setup.url),
|
||||
additional_headers={**setup.headers, **setup.cookies.as_header(setup)},
|
||||
proxy=setup.proxy if setup.proxy is not None else True,
|
||||
**timeout_kwargs, # type: ignore
|
||||
**kwargs, # type: ignore
|
||||
)
|
||||
async with connection as ws:
|
||||
yield WebSocket(request=setup, websocket=ws)
|
||||
|
||||
Reference in New Issue
Block a user