Skip to content

Commit 6cbaed1

Browse files
committed
Add HTTP/HTTPS proxy support via environment variables
1 parent d8cca8d commit 6cbaed1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

massive/rest/base.py

Lines changed: 12 additions & 3 deletions
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,
75-
headers=self.headers, # default headers sent with each request.
76+
headers=self.headers,
7677
ca_certs=certifi.where(),
7778
cert_reqs="CERT_REQUIRED",
78-
retries=retry_strategy, # use the customized Retry instance
79+
retries=retry_strategy,
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)