Feature: 为 HTTPClient 等内置驱动器添加流式请求方法 (#3560)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Ailitonia
2025-07-05 20:54:03 +08:00
committed by GitHub
parent 3f24e3dfac
commit f6ae2b8698
4 changed files with 287 additions and 0 deletions

View File

@ -255,6 +255,17 @@ class HTTPClientSession(abc.ABC):
"""发送一个 HTTP 请求"""
raise NotImplementedError
@abc.abstractmethod
async def stream_request(
self,
setup: Request,
*,
chunk_size: int = 1024,
) -> AsyncGenerator[Response, None]:
"""发送一个 HTTP 流式请求"""
raise NotImplementedError
yield # used for static type checking's generator detection
@abc.abstractmethod
async def setup(self) -> None:
"""初始化会话"""
@ -286,6 +297,17 @@ class HTTPClientMixin(ForwardMixin):
"""发送一个 HTTP 请求"""
raise NotImplementedError
@abc.abstractmethod
async def stream_request(
self,
setup: Request,
*,
chunk_size: int = 1024,
) -> AsyncGenerator[Response, None]:
"""发送一个 HTTP 流式请求"""
raise NotImplementedError
yield # used for static type checking's generator detection
@abc.abstractmethod
def get_session(
self,