Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: Fix no_proxy env variable parsing #59

Merged
merged 1 commit into from
Jul 28, 2024
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: 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
11 changes: 11 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ 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
Loading