Skip to content

Commit

Permalink
优化httpx client参数生成
Browse files Browse the repository at this point in the history
  • Loading branch information
auqhjjqdo committed Jan 11, 2024
1 parent ecd6364 commit 8751e4a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions live_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ async def request(self, method, url, **kwargs):
raise ConnectionError(f'{self.flag}直播检测请求错误\n{repr(error)}')

def get_client(self):
client_kwargs = {
'http2': True,
'timeout': self.interval,
'limits': httpx.Limits(max_keepalive_connections=100, keepalive_expiry=self.interval * 2),
'headers': self.headers,
'cookies': self.cookies
}
# 检查是否有设置代理
if self.proxy:
transport = AsyncProxyTransport.from_url(self.proxy)
else:
transport = None

return httpx.AsyncClient(
http2=True,
timeout=self.interval,
limits=httpx.Limits(max_keepalive_connections=100, keepalive_expiry=self.interval * 2),
transport=transport,
headers=self.headers,
cookies=self.cookies
)
if 'socks' in self.proxy:
client_kwargs['transport'] = AsyncProxyTransport.from_url(self.proxy)
else:
client_kwargs['proxies'] = self.proxy
return httpx.AsyncClient(**client_kwargs)

def get_cookies(self):
if self.cookies:
Expand Down

0 comments on commit 8751e4a

Please sign in to comment.