4848logger .setLevel (logging .INFO )
4949
5050
51+ PROXY_MOUNT = Dict [str , Union [httpx .BaseTransport , None ]]
52+
53+
5154# Future work:
5255# Consider use "verbose" settings to control default logging output level
5356# by doing this instead of using branching throughout the application,
@@ -100,6 +103,12 @@ async def _build_http_client(self, cache_db: Union[str, Path] = None) -> None:
100103 This modifies the state of the BiothingsClient instance
101104 to set the values for the http_client property
102105
106+ For the moment, we have disabled timeouts. This matches our prior
107+ behavior we had with the requests library, which by default did not
108+ specify a timeout when making a request. In the future this should
109+ be modified to prevent indefinite hanging with potentially bad network
110+ connections
111+
103112 Inputs:
104113 :param cache_db: pathlike object to the local sqlite3 cache database file
105114
@@ -108,6 +117,7 @@ async def _build_http_client(self, cache_db: Union[str, Path] = None) -> None:
108117 """
109118 if not self .http_client_setup :
110119 self .http_client = httpx .AsyncClient ()
120+ self .http_client = httpx .AsyncClient (timeout = None )
111121 self .http_client_setup = True
112122 self .http_cache_client_setup = False
113123
@@ -121,6 +131,12 @@ async def _build_cache_http_client(self, cache_db: Union[str, Path] = None) -> N
121131 This modifies the state of the BiothingsClient instance
122132 to set the values for the http_client property and the cache_storage property
123133
134+ For the moment, we have disabled timeouts. This matches our prior
135+ behavior we had with the requests library, which by default did not
136+ specify a timeout when making a request. In the future this should
137+ be modified to prevent indefinite hanging with potentially bad network
138+ connections
139+
124140 Inputs:
125141 :param cache_db: pathlike object to the local sqlite3 cache database file
126142
@@ -134,15 +150,47 @@ async def _build_cache_http_client(self, cache_db: Union[str, Path] = None) -> N
134150
135151 self .cache_storage = AsyncBiothingsClientSqlite3Cache ()
136152 await self .cache_storage .setup_database_connection (cache_db )
137- cache_transport = hishel . AsyncCacheTransport (
138- transport = httpx .AsyncHTTPTransport (), storage = self . cache_storage
139- )
153+
154+ async_http_transport = httpx .AsyncHTTPTransport ()
155+ cache_transport = hishel . AsyncCacheTransport ( transport = async_http_transport , storage = self . cache_storage )
140156 cache_controller = hishel .Controller (cacheable_methods = ["GET" , "POST" ])
157+
158+ # Have to manually build the proxy mounts as httpx will not auto-discover
159+ # proxies if we provide our own HTTPTransport to the Client constructor
160+ proxy_mounts = self ._build_caching_proxy_mounts ()
141161 self .http_client = hishel .AsyncCacheClient (
142- controller = cache_controller , transport = cache_transport , storage = self .cache_storage
162+ controller = cache_controller ,
163+ transport = cache_transport ,
164+ storage = self .cache_storage ,
165+ mounts = proxy_mounts ,
166+ timeout = None ,
143167 )
144168 self .http_client_setup = True
145169
170+ def _build_caching_proxy_mounts (self ) -> PROXY_MOUNT :
171+ """
172+ Builds the proxy mounts for case where we have a CacheTransport.
173+ Autodiscovery of proxies only works when don't provide a transport
174+ to the client so this method acts as a replacement for that
175+ """
176+ proxy_map = httpx ._utils .get_environment_proxies ()
177+ proxy_mounts : PROXY_MOUNT = {}
178+ for key , proxy in proxy_map .items ():
179+ proxy_transport = None
180+ if proxy is not None :
181+ proxy_transport = httpx .AsyncHTTPTransport (
182+ verify = True ,
183+ cert = None ,
184+ trust_env = True ,
185+ http1 = True ,
186+ http2 = False ,
187+ limits = httpx ._config .DEFAULT_LIMITS ,
188+ proxy = proxy ,
189+ )
190+ proxy_mounts [key ] = proxy_transport
191+ proxy_mounts = dict (sorted (proxy_mounts .items ()))
192+ return proxy_mounts
193+
146194 async def __del__ (self ):
147195 """
148196 Destructor for the client to ensure that we close any potential
0 commit comments