Skip to content

*.example.com in NO_PROXY never bypasses the proxy #1276

Closed

Description

@RaphaelFakhri

NO_PROXY entries written as *.example.com have no effect. Requests to subdomains of example.com still go through the proxy, and no error is raised.

get_environment_proxies() prepends * to every plain hostname entry, so *.example.com becomes the mount key all://**.example.com. URLPattern then escapes the remaining * and builds the regex ^(.+\.)?\*\.example\.com$, which matches no real hostname.

import os
import httpx2

os.environ["HTTPS_PROXY"] = "http://proxy.invalid:3128"
os.environ["NO_PROXY"] = "*.example.com"

print(httpx2._utils.get_environment_proxies())
# {'https://': 'http://proxy.invalid:3128', 'all://**.example.com': None}

client = httpx2.Client()
print(client._transport_for_url(httpx2.URL("https://www.example.com")))
# The proxy transport, not the direct one.

The *. form is common in NO_PROXY values (it is what the Windows and macOS bypass lists use, and many corporate setups copy it into the environment). Go's net/http treats *.example.com the same as .example.com, which matches subdomains only. NO_PROXY=.example.com already works that way in HTTPX2.

Reproduced on main (2.14.0), Python 3.12, Linux.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions