From cd5027cfd89f66b9070ba5d8d301e97d23ac0bee Mon Sep 17 00:00:00 2001 From: Kevin Chiu Date: Sat, 29 Nov 2025 21:56:07 -0800 Subject: [PATCH] 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. --- massive/rest/base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/massive/rest/base.py b/massive/rest/base.py index 66c28924..72072429 100644 --- a/massive/rest/base.py +++ b/massive/rest/base.py @@ -1,5 +1,6 @@ import certifi import json +import os import urllib3 import inspect from urllib3.util.retry import Retry @@ -70,7 +71,7 @@ def __init__( # https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html # https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool - self.client = urllib3.PoolManager( + pool_kwargs = dict( num_pools=num_pools, headers=self.headers, # default headers sent with each request. ca_certs=certifi.where(), @@ -78,6 +79,14 @@ def __init__( retries=retry_strategy, # use the customized Retry instance ) + # Check for proxy environment variables (HTTPS_PROXY or HTTP_PROXY) + proxy_url = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy") \ + or os.environ.get("HTTP_PROXY") or os.environ.get("http_proxy") + if proxy_url: + self.client = urllib3.ProxyManager(proxy_url, **pool_kwargs) + else: + self.client = urllib3.PoolManager(**pool_kwargs) + self.timeout = urllib3.Timeout(connect=connect_timeout, read=read_timeout) if verbose: