Skip to content

Commit c496631

Browse files
Fix #1082 by ignoring proxy parameter if env parameter is set but empty (#1083)
1 parent c678018 commit c496631

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

slack_sdk/proxy_env_variable_loader.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ def load_http_proxy_from_env(logger: logging.Logger = _default_logger) -> Option
1313
or os.environ.get("HTTP_PROXY")
1414
or os.environ.get("http_proxy")
1515
)
16-
if proxy_url is not None:
16+
if proxy_url is None:
17+
return None
18+
if len(proxy_url.strip()) == 0:
19+
# If the value is an empty string, the intention should be unsetting it
1720
logger.debug(
18-
f"HTTP proxy URL has been loaded from an env variable: {proxy_url}"
21+
"The Slack SDK ignored the proxy env variable as an empty value is set."
1922
)
23+
return None
24+
25+
logger.debug(f"HTTP proxy URL has been loaded from an env variable: {proxy_url}")
2026
return proxy_url

tests/test_proxy_env_variable_loader.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ def test_load_upper_case(self):
2222
os.environ["HTTPS_PROXY"] = "http://localhost:9999"
2323
url = load_http_proxy_from_env()
2424
self.assertEqual(url, "http://localhost:9999")
25+
26+
def test_load_all_empty_case(self):
27+
os.environ["HTTP_PROXY"] = ""
28+
os.environ["http_proxy"] = ""
29+
os.environ["HTTPS_PROXY"] = ""
30+
os.environ["https_proxy"] = ""
31+
url = load_http_proxy_from_env()
32+
self.assertEqual(url, None)
33+
34+
def test_proxy_url_is_none_case(self):
35+
os.environ.pop("HTTPS_PROXY", None)
36+
os.environ.pop("https_proxy", None)
37+
os.environ.pop("HTTP_PROXY", None)
38+
os.environ.pop("http_proxy", None)
39+
url = load_http_proxy_from_env()
40+
self.assertEqual(url, None)

0 commit comments

Comments
 (0)