From 52c02871507d47ab8f5086e25f82824dcf49beef Mon Sep 17 00:00:00 2001 From: ihmily <114978440+ihmily@users.noreply.github.com> Date: Tue, 4 Feb 2025 06:54:14 +0800 Subject: [PATCH] perf: add http2 tcp request --- douyinliverecorder/http_clients/async_http.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/douyinliverecorder/http_clients/async_http.py b/douyinliverecorder/http_clients/async_http.py index 7ec5af9..92fb1c6 100644 --- a/douyinliverecorder/http_clients/async_http.py +++ b/douyinliverecorder/http_clients/async_http.py @@ -20,16 +20,17 @@ async def async_req( abroad: bool = False, content_conding: str = 'utf-8', verify: bool = False, + http2: bool = True ) -> OptionalDict | OptionalStr | tuple: if headers is None: headers = {} try: proxy_addr = utils.handle_proxy_addr(proxy_addr) if data or json_data: - async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify) as client: + async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify, http2=http2) as client: response = await client.post(url, data=data, json=json_data, headers=headers) else: - async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify) as client: + async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify, http2=http2) as client: response = await client.get(url, headers=headers, follow_redirects=True) if redirect_url: @@ -46,7 +47,7 @@ async def async_req( async def get_response_status(url: str, proxy_addr: OptionalStr = None, headers: OptionalDict = None, - timeout: int = 10, abroad: bool = False, verify: bool = False) -> bool: + timeout: int = 10, abroad: bool = False, verify: bool = False, http2=False) -> bool: try: proxy_addr = utils.handle_proxy_addr(proxy_addr)