Skip to content

Commit

Permalink
fix: Swap out custom NO_PROXY handling for urllib.request.proxy_bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
jbw-vtl committed Dec 30, 2024
1 parent 6d68d56 commit 195aba2
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/prefect/events/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
cast,
)
from urllib.parse import urlparse
from urllib.request import proxy_bypass
from uuid import UUID

import orjson
Expand Down Expand Up @@ -84,20 +85,6 @@ def events_out_socket_from_api_url(url: str):
return http_to_ws(url) + "/events/out"


def _host_matches_no_proxy(host: str) -> bool:
"""Checks whether a given host matches NO_PROXY configuration.
NO_PROXY entries with a leading dot are treated as domain suffixes, while all others are treated as exact matches.
"""
if no_proxy := os.environ.get("NO_PROXY"):
for no_proxy_host in no_proxy.split(","):
if no_proxy_host.startswith("."):
if host.endswith(no_proxy_host):
return True
elif no_proxy_host == host:
return True
return False


class WebsocketProxyConnect(Connect):
def __init__(self: Self, uri: str, **kwargs: Any):
# super() is intentionally deferred to the _proxy_connect method
Expand Down Expand Up @@ -125,9 +112,7 @@ def __init__(self: Self, uri: str, **kwargs: Any):
)

self._proxy = (
Proxy.from_url(proxy_url)
if proxy_url and not _host_matches_no_proxy(host)
else None
Proxy.from_url(proxy_url) if proxy_url and not proxy_bypass(host) else None
)
self._host = host
self._port = port
Expand Down

0 comments on commit 195aba2

Please sign in to comment.