Skip to content

Respect no_proxy environment variable - #2171

Open
Sanjays2402 wants to merge 2 commits into
apache:trunkfrom
Sanjays2402:fix/2077-respect-no-proxy
Open

Respect no_proxy environment variable#2171
Sanjays2402 wants to merge 2 commits into
apache:trunkfrom
Sanjays2402:fix/2077-respect-no-proxy

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Respect no_proxy environment variable

Description

Fixes #2077.

When a proxy is configured explicitly (via set_http_proxy() or the http_proxy /
https_proxy environment variables), libcloud used it for every request, including
hosts listed in no_proxy / NO_PROXY. Other HTTP clients (curl, requests via its
own env handling, urllib) all honour no_proxy, so this was surprising and made it
impossible to talk to an internal endpoint directly while a proxy was configured.

This adds a _proxies_for_url(url) helper on LibcloudBaseConnection that returns
an empty proxy mapping ({}) when the target host matches no_proxy, and None
otherwise so the session default applies. It is passed as proxies= in
LibcloudConnection.request(). Matching is delegated to requests.utils.should_bypass_proxies,
so libcloud inherits the exact same no_proxy semantics as requests rather than
reimplementing them.

Status

done, ready for review

Checklist (tick everything that applies)

  • Code linting (required, can be done after the PR checks)
  • Documentation
  • Tests
  • ICLA (required for bigger changes)

Sanjays2402 and others added 2 commits July 24, 2026 19:53
An explicitly configured proxy was used for every request, even when the
target host matched the no_proxy / NO_PROXY environment variable. Add a
_proxies_for_url helper that returns an empty proxy mapping for bypassed
hosts so libcloud behaves consistently with other HTTP clients.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new regression test’s environment cleanup can leak no_proxy state (and doesn’t isolate NO_PROXY), potentially causing flaky tests or side effects across the test suite.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates Libcloud’s Requests integration so that explicitly configured proxies (via set_http_proxy() / proxy_url) are bypassed for targets matching no_proxy / NO_PROXY, aligning behavior with Requests/curl/urllib semantics.

Changes:

  • Add LibcloudBaseConnection._proxies_for_url(url) to selectively disable proxies when should_bypass_proxies() indicates no_proxy should apply.
  • Pass proxies= per-request in LibcloudConnection.request() to allow bypass behavior for matching hosts.
  • Add a regression test and a CHANGES entry documenting the behavior change.
File summaries
File Description
libcloud/http.py Adds per-URL proxy selection and wires it into requests made by LibcloudConnection.
libcloud/test/test_connection.py Adds a regression test validating proxy bypass behavior for no_proxy hosts.
CHANGES.rst Documents the new no_proxy/NO_PROXY proxy-bypass behavior.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +167 to +168
os.environ["no_proxy"] = "internal.example.com"
self.addCleanup(os.environ.pop, "no_proxy", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sanjays2402, could you take a look?

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

Successfully merging this pull request may close these issues.

Respect no_proxy environment variable

3 participants