From 99301d2d6e07240b5866e354fc9745f1614114e8 Mon Sep 17 00:00:00 2001 From: Jon Bramley Date: Wed, 25 Feb 2026 10:00:09 +0000 Subject: [PATCH] Manages HTTP proxy environment variables Conditionally sets HTTP and HTTPS proxy environment variables if a proxy is configured. If no proxy is specified in the configuration, it explicitly removes these environment variables. This prevents the application from attempting to use a potentially invalid or non-existent proxy when one is not intended to be used. --- app/main.py | 8 ++++++-- app/test_main.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 0e1163d..faf00fb 100644 --- a/app/main.py +++ b/app/main.py @@ -37,8 +37,12 @@ async def lifespan(_: FastAPI): def main() -> None: # pragma: no cover - os.environ["HTTP_PROXY"] = str(config.http_proxy) - os.environ["HTTPS_PROXY"] = str(config.http_proxy) + if config.http_proxy: + os.environ["HTTP_PROXY"] = str(config.http_proxy) + os.environ["HTTPS_PROXY"] = str(config.http_proxy) + else: + os.environ.pop("HTTP_PROXY", None) + os.environ.pop("HTTPS_PROXY", None) uvicorn.run( "app.main:app", diff --git a/app/test_main.py b/app/test_main.py index 8d846ce..7472ea5 100644 --- a/app/test_main.py +++ b/app/test_main.py @@ -71,5 +71,5 @@ def test_main_no_proxy_in_config(mocker, monkeypatch): main_mod.main() - assert os.environ.get("HTTP_PROXY") == "None" - assert os.environ.get("HTTPS_PROXY") == "None" + assert os.environ.get("HTTP_PROXY") is None + assert os.environ.get("HTTPS_PROXY") is None