Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tests/test_http_file_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from toolkit.core.exceptions import DownloadError
from toolkit.plugins.http_file import (
HttpFileSource,
_get_proxy_from_env,
_sanitize_proxy_url,
_parse_curl_status,
_strip_curl_status,
Expand Down Expand Up @@ -281,16 +282,20 @@ def test_fallback_on_timeout_with_proxy(self):
err=TimeoutError("connect timed out"),
ssl_fallback_used=False,
)

source = HttpFileSource(retries=1)
source._client = fake

with mock.patch.dict(os.environ, {"HTTPS_PROXY": "http://proxy:8888"}):
with mock.patch(
"toolkit.plugins.http_file._fetch_via_curl",
return_value=b"curl-data",
) as mock_curl:
payload = source.fetch("https://example.test/data.csv")

assert payload == b"curl-data"
mock_curl.assert_called_once()

@pytest.mark.contract
@pytest.mark.regression # toolkit#414
def test_get_proxy_env_blocked_source(self):
"""_get_proxy_from_env legge BLOCKED_SOURCE_PROXY."""
with mock.patch.dict(os.environ, {"BLOCKED_SOURCE_PROXY": "http://proxy:8888"}, clear=True):
assert _get_proxy_from_env() == "http://proxy:8888"
8 changes: 6 additions & 2 deletions toolkit/plugins/http_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ def _sanitize_proxy_url(proxy: str) -> str:


def _get_proxy_from_env() -> str | None:
"""Legge HTTPS_PROXY dall'ambiente (lowercase/uppercase)."""
return os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy")
"""Legge HTTPS_PROXY o BLOCKED_SOURCE_PROXY dall'ambiente."""
return (
os.environ.get("HTTPS_PROXY")
or os.environ.get("https_proxy")
or os.environ.get("BLOCKED_SOURCE_PROXY")
)


def _fetch_via_curl(
Expand Down
Loading