From c44c8d2503f7081673f7aade3939ea45d8307f58 Mon Sep 17 00:00:00 2001 From: ksieuk Date: Sat, 7 Oct 2023 01:56:46 +0300 Subject: [PATCH] feat: [#38] class inherits all methods of httpx.Asynclient --- src/assistant/lib/clients/http_client.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/assistant/lib/clients/http_client.py b/src/assistant/lib/clients/http_client.py index 3a0b855..efc6a53 100644 --- a/src/assistant/lib/clients/http_client.py +++ b/src/assistant/lib/clients/http_client.py @@ -5,7 +5,7 @@ import httpx import lib.app.split_settings as app_split_settings -class AsyncHttpClient: +class AsyncHttpClient(httpx.AsyncClient): def __init__( self, proxy_settings: app_split_settings.ProxySettings, @@ -17,7 +17,7 @@ class AsyncHttpClient: self.proxies = self.__get_proxies_from_settings() self.client_params = client_params - self.client = self._get_client() + super().__init__(base_url=self.base_url, proxies=self.proxies, **client_params) def __get_proxies_from_settings(self) -> dict[str, str] | None: if not self.proxy_settings.enable: @@ -25,14 +25,5 @@ class AsyncHttpClient: proxies = {"all://": self.proxy_settings.dsn} return proxies - def _get_client(self): - return httpx.AsyncClient( - base_url=self.base_url, - proxies=self.proxies, # type: ignore - **self.client_params, - ) - - async def close(self): - if not self.client: - return - await self.client.aclose() + async def close(self) -> None: + await self.aclose()