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

no_proxy is inconsistent with urllib and makes mixing libraries HAVE to put . when not needed if this library is not in use. #968

Open
MikeMoore63 opened this issue Jan 16, 2024 · 0 comments

Comments

@MikeMoore63
Copy link

MikeMoore63 commented Jan 16, 2024

I have read issue #700 and read the argument the ucrrent implementation is "more flexible". Having been burnt with this just recently I would argue the inconsistency is worse.

If you use a black box application that includes requests and then adds websocket support using this library things go horribly wrong. I eventually traced the issues to the nigh on unique approach websockets takes to handling no_proxy.

Appreciate its inconsistent please read https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/ for more on the issues.

Please read the "lowest common denominator" which unfortunately the websocket-client does not meet. I was religously following this.

Googles gcloud supports proxies and I had been using it for years with no_proxy with domains with no ".". All was well until 2 weeks ago when i started using a new feature for tunnelling that uses this client. This was the only feature that did not work. It took me debugging the gcloud to eventually work out this library was even part of gcloud and its has this apparently nigh on unique implementation of no_proxy.

I would expect this to simply be consistent with all other python implementations it is currently consistent with curl but not wget. So consistent with urllib https://github.com/python/cpython/blob/030a713183084594659aefd77b76fe30178e23c8/Lib/urllib/request.py#L2548

# check if the host ends with any of the DNS suffixes
    for name in no_proxy.split(','):
        name = name.strip()
        if name:
            name = name.lstrip('.')  # ignore leading dots
            name = name.lower()
            if hostonly == name or host == name:
                return True
            name = '.' + name
            if hostonly.endswith(name) or host.endswith(name):
                return True

vs

for domain in [domain for domain in no_proxy if domain.startswith(".")]:

    if not no_proxy:
        if v := os.environ.get("no_proxy", os.environ.get("NO_PROXY", "")).replace(
            " ", ""
        ):
            no_proxy = v.split(",")
    if not no_proxy:
        no_proxy = DEFAULT_NO_PROXY_HOST

    if "*" in no_proxy:
        return True
    if hostname in no_proxy:
        return True
    if _is_ip_address(hostname):
        return any(
            [
                _is_address_in_network(hostname, subnet)
                for subnet in no_proxy
                if _is_subnet_address(subnet)
            ]
        )
    for domain in [domain for domain in no_proxy if domain.startswith(".")]:
        if hostname.endswith(domain):
            return True

instead the "." should be removed and checks done against endwith for consistencies sake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant