2525from email .utils import parsedate_to_datetime
2626from enum import Enum
2727from time import sleep
28- from typing import Dict , Iterable , Mapping , Optional , Union
28+ from typing import Dict , Iterable , Mapping , Optional , Type , Union
2929from urllib .parse import urlencode , urlparse , urlunparse
3030
3131import httpx
@@ -236,7 +236,9 @@ async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
236236 return response
237237
238238
239- def async_http_client (config : schemas .ConnectionConfig = None ) -> httpx .AsyncClient :
239+ def async_http_client (
240+ config : schemas .ConnectionConfig = None
241+ ) -> httpx .AsyncClient :
240242 """
241243 Create an async HTTPX client
242244 :param config: a connection config
@@ -250,14 +252,20 @@ def async_http_client(config: schemas.ConnectionConfig = None) -> httpx.AsyncCli
250252 )
251253 transport = RetryTransport (
252254 AsyncHTTPTransport (
253- retries = config .connection_retries , verify = config .verify , http2 = config .http2
255+ retries = config .connection_retries ,
256+ verify = config .verify ,
257+ http2 = config .http2
254258 ),
255259 max_attempts = config .max_attempts ,
256260 )
257- return httpx .AsyncClient (timeout = config .timeout , transport = transport )
261+ return config .async_httpx_class (timeout = config .timeout ,
262+ transport = transport )
258263
259264
260- def http_client (config : schemas .ConnectionConfig = None ) -> httpx .Client :
265+ def http_client (
266+ config : schemas .ConnectionConfig = None ,
267+ cls : Optional [Type [httpx .Client ]] = httpx .Client
268+ ) -> httpx .Client :
261269 """
262270 Create an HTTPX client
263271 :param config: a connection config
@@ -271,11 +279,13 @@ def http_client(config: schemas.ConnectionConfig = None) -> httpx.Client:
271279 )
272280 transport = RetryTransport (
273281 HTTPTransport (
274- retries = config .connection_retries , verify = config .verify , http2 = config .http2
282+ retries = config .connection_retries ,
283+ verify = config .verify ,
284+ http2 = config .http2
275285 ),
276286 max_attempts = config .max_attempts ,
277287 )
278- return httpx . Client (timeout = config .timeout , transport = transport )
288+ return config . httpx_class (timeout = config .timeout , transport = transport )
279289
280290
281291def build_url (base_api_url : str , path : str , query_dict : Optional [dict ]):
0 commit comments