Skip to content

Commit cd5027c

Browse files
committed
Add HTTP proxy support via environment variables
When HTTPS_PROXY, https_proxy, HTTP_PROXY, or http_proxy environment variables are set, use urllib3.ProxyManager instead of PoolManager. This enables the client to work in environments that require proxy configuration, such as corporate networks, CI/CD pipelines, and sandboxed development environments. The behavior is backward compatible - when no proxy environment variables are set, PoolManager is used as before.
1 parent d8cca8d commit cd5027c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

massive/rest/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import certifi
22
import json
3+
import os
34
import urllib3
45
import inspect
56
from urllib3.util.retry import Retry
@@ -70,14 +71,22 @@ def __init__(
7071

7172
# https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html
7273
# https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool
73-
self.client = urllib3.PoolManager(
74+
pool_kwargs = dict(
7475
num_pools=num_pools,
7576
headers=self.headers, # default headers sent with each request.
7677
ca_certs=certifi.where(),
7778
cert_reqs="CERT_REQUIRED",
7879
retries=retry_strategy, # use the customized Retry instance
7980
)
8081

82+
# Check for proxy environment variables (HTTPS_PROXY or HTTP_PROXY)
83+
proxy_url = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy") \
84+
or os.environ.get("HTTP_PROXY") or os.environ.get("http_proxy")
85+
if proxy_url:
86+
self.client = urllib3.ProxyManager(proxy_url, **pool_kwargs)
87+
else:
88+
self.client = urllib3.PoolManager(**pool_kwargs)
89+
8190
self.timeout = urllib3.Timeout(connect=connect_timeout, read=read_timeout)
8291

8392
if verbose:

0 commit comments

Comments
 (0)