You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by "Sanjays2402 (via GitHub)" <gi...@apache.org> on 2026/07/25 02:54:10 UTC
[PR] Respect no_proxy environment variable [libcloud]
Sanjays2402 opened a new pull request, #2171:
URL: https://github.com/apache/libcloud/pull/2171
## 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)
- [x] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide) (required, can be done after the PR checks)
- [ ] Documentation
- [x] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
- [ ] [ICLA](http://libcloud.readthedocs.org/en/latest/development.html#contributing-bigger-changes) (required for bigger changes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "Sanjays2402 (via GitHub)" <gi...@apache.org>.
Sanjays2402 commented on PR #2171:
URL: https://github.com/apache/libcloud/pull/2171#issuecomment-5612864218
You're right — I traced it through requests' source and confirmed: Session.request() runs merge_setting(proxies, self.proxies), so passing {} merged the session-level proxy straight back in. I verified this locally: merge_setting({}, session_proxies) returns the session proxies, while merge_setting({'http': None, 'https': None}, session_proxies) strips the None values and yields an empty mapping. Fixed in 34fd511 — _proxies_for_url() now returns {'http': None, 'https': None} when bypassing, and I added the end-to-end-ish test you asked for: it mocks HTTPAdapter.send, drives LibcloudConnection.request(), and asserts the proxy mapping that actually reaches the adapter (no session proxy leaked, select_proxy() returns None), plus a control case proving non-bypassed hosts still use the configured proxy. The new test fails on the old code and passes on the new.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "micafer (via GitHub)" <gi...@apache.org>.
micafer merged PR #2171:
URL: https://github.com/apache/libcloud/pull/2171
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "Sanjays2402 (via GitHub)" <gi...@apache.org>.
Sanjays2402 commented on PR #2171:
URL: https://github.com/apache/libcloud/pull/2171#issuecomment-5597178722
Thanks @micafer — good catch. The test now snapshots both no_proxy and NO_PROXY up front, pins NO_PROXY to unset for the test's duration, and the addCleanup restores the original values instead of unconditionally popping no_proxy after tearDown. The externally-set NO_PROXY case you (and Copilot) flagged can't leak in or out anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "Sanjays2402 (via GitHub)" <gi...@apache.org>.
Sanjays2402 commented on PR #2171:
URL: https://github.com/apache/libcloud/pull/2171#issuecomment-5614859817
Done — ran black and flake8 (repo configs) over the PR's files in 47df9a4. The two files needed minor reformatting (extra blank line, a couple of over-wrapped asserts); flake8 is clean now and the connection tests still pass (28/28; the one timeout-test failure is pre-existing on trunk and unrelated).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "micafer (via GitHub)" <gi...@apache.org>.
micafer commented on PR #2171:
URL: https://github.com/apache/libcloud/pull/2171#issuecomment-5614131826
Hi @Sanjays2402,
There are some minor lint, and black style errors. Could you take a look?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2171:
URL: https://github.com/apache/libcloud/pull/2171#issuecomment-5613972755
## [Codecov](https://app.codecov.io/gh/apache/libcloud/pull/2171?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `90.00000%` with `6 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 83.60%. Comparing base ([`dc57f81`](https://app.codecov.io/gh/apache/libcloud/commit/dc57f81468386afffb59c687180e0cf0f703c146?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`34fd511`](https://app.codecov.io/gh/apache/libcloud/commit/34fd511cb0600ce6c1f9710f02b849518510a05d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/libcloud/pull/2171?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [libcloud/test/test\_connection.py](https://app.codecov.io/gh/apache/libcloud/pull/2171?src=pr&el=tree&filepath=libcloud%2Ftest%2Ftest_connection.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bGliY2xvdWQvdGVzdC90ZXN0X2Nvbm5lY3Rpb24ucHk=) | 88.89% | [3 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/libcloud/pull/2171?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## trunk #2171 +/- ##
=======================================
Coverage 83.59% 83.60%
=======================================
Files 352 352
Lines 81866 81926 +60
Branches 8773 8783 +10
=======================================
+ Hits 68433 68487 +54
- Misses 10561 10564 +3
- Partials 2872 2875 +3
```
| [Files with missing lines](https://app.codecov.io/gh/apache/libcloud/pull/2171?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [libcloud/http.py](https://app.codecov.io/gh/apache/libcloud/pull/2171?src=pr&el=tree&filepath=libcloud%2Fhttp.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bGliY2xvdWQvaHR0cC5weQ==) | `92.41% <100.00%> (+0.33%)` | :arrow_up: |
| [libcloud/test/test\_connection.py](https://app.codecov.io/gh/apache/libcloud/pull/2171?src=pr&el=tree&filepath=libcloud%2Ftest%2Ftest_connection.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bGliY2xvdWQvdGVzdC90ZXN0X2Nvbm5lY3Rpb24ucHk=) | `96.65% <88.89%> (-0.99%)` | :arrow_down: |
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Respect no_proxy environment variable [libcloud]
Posted by "micafer (via GitHub)" <gi...@apache.org>.
micafer commented on code in PR #2171:
URL: https://github.com/apache/libcloud/pull/2171#discussion_r3911448046
##########
libcloud/test/test_connection.py:
##########
@@ -161,6 +161,18 @@ def test_constructor(self):
{"http": "https://127.0.0.6:3129", "https": "https://127.0.0.6:3129"},
)
+ def test_proxy_is_bypassed_for_no_proxy_hosts(self):
+ # Regression test for GITHUB-2077: an explicitly configured proxy must
+ # not be used for hosts listed in the no_proxy environment variable.
+ os.environ["no_proxy"] = "internal.example.com"
+ self.addCleanup(os.environ.pop, "no_proxy", None)
Review Comment:
Hi @Sanjays2402, could you take a look?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org