Skip to content

Commit 3d2a238

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 3c247d7 commit 3d2a238

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎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
@@ -73,7 +74,7 @@ def __init__(
7374

7475
# https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html
7576
# https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool
76-
self.client = urllib3.PoolManager(
77+
pool_kwargs = dict(
7778
num_pools=num_pools,
7879
headers=self.headers, # default headers sent with each request.
7980
ca_certs=certifi.where(),
@@ -82,6 +83,14 @@ def __init__(
8283
timeout=self.timeout, # set timeout for each request
8384
)
8485

86+
# Check for proxy environment variables (HTTPS_PROXY or HTTP_PROXY)
87+
proxy_url = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy") \
88+
or os.environ.get("HTTP_PROXY") or os.environ.get("http_proxy")
89+
if proxy_url:
90+
self.client = urllib3.ProxyManager(proxy_url, **pool_kwargs)
91+
else:
92+
self.client = urllib3.PoolManager(**pool_kwargs)
93+
8594
if verbose:
8695
logger.setLevel(logging.DEBUG)
8796
self.trace = trace

0 commit comments

Comments
 (0)