Skip to content

Commit

Permalink
http: Fix no_proxy env variable parsing
Browse files Browse the repository at this point in the history
Don't parse no_proxy as a URL, because it's just a pattern. This fixes
an error, when no_proxy is set:

    ValueError: Unknown scheme ""
  • Loading branch information
holesch committed Jul 28, 2024
1 parent 52d5b8a commit 556be21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions not_my_board/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ def __init__(self, ca_files=None, proxies=None):

if proxies is None:
proxies = urllib.request.getproxies()
self._proxies = {
scheme: self._parse_url(url) for scheme, url in proxies.items()
}

self._proxies = {}
for scheme in ("http", "https"):
if scheme in proxies:
self._proxies[scheme] = self._parse_url(proxies[scheme])
self._no_proxy = proxies.get("no", "")

async def get_json(self, url):
return await self._request_json("GET", url)
Expand Down Expand Up @@ -125,7 +128,7 @@ async def _connect(self, url):

def _get_proxy(self, url):
proxy = self._proxies.get(url.scheme)
if proxy and not is_proxy_disabled(url.host, self._proxies.get("no", "")):
if proxy and not is_proxy_disabled(url.host, self._no_proxy):
return proxy
return None

Expand Down
9 changes: 9 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ async def test_proxy_connect(tinyproxy):
assert response == {"places": []}


async def test_proxy_ignore():
async with sh_task("not-my-board hub", "hub"):
await wait_for_ports(2092)

client = http.Client(proxies={"http": "http://non-existing.localhost", "no": "127.0.0.1"})
response = await client.get_json("http://127.0.0.1:2092/api/v1/places")
assert response == {"places": []}


async def test_proxy_connect_https(tinyproxy):
root_key = project_dir / "tests/.cache/not-my-board-root-ca.key"
root_cert = project_dir / "tests/.cache/not-my-board-root-ca.crt"
Expand Down

0 comments on commit 556be21

Please sign in to comment.