-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for the no_proxy
env var mechanism in the HTTP client
#4445
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4445 +/- ##
=======================================
Coverage 97.17% 97.17%
=======================================
Files 41 41
Lines 8854 8863 +9
Branches 1424 1425 +1
=======================================
+ Hits 8604 8613 +9
Misses 133 133
Partials 117 117
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Interested in this too! |
Not sure why the linter is failing. Any pointers? |
The log is here https://github.com/aio-libs/aiohttp/pull/4445/checks?check_run_id=1827835221#step:6:60 Also, you can run the pre-commit.com tool locally to see the same. |
Figures, doesn't fail locally when I run pre-commit. Github
Local
It's definitely there proxy_bypass. |
Hi there, could anyone estimate when there will be a chance to merge and release this fix? |
I suppose the CI pulls-in newer code from master. You should probably rebase to get the same errors locally.
Once merged, this will need to be backported to the 3.8 branch and then we'd need to make that branch release-worthy which requires quite a bit of work to at least stabilize the CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few suggestions to improve the structure. And this will also need some accompanying tests and docs changes. It's important to understand how this feature is supposed to be used by the users.
Also, it looks more like a feature so we should probably rename the change fragment to .feature
instead of .bugfix
.
tests/test_helpers.py
Outdated
"http_proxy": ["http://example.com"], | ||
"HTTP_PROXY": ["http://example.com"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why it's necessary to have both spellings in the same test. It could be reasonable to test them separately, though. And maybe have different spellings with different values testing which one overrides another.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the case difference? If I remember correctly (been awhile, I'll go check) but there's no spec. for the proxy info, it's just by convention. And there's more than one; one with lower case and the other upper. I think there's even all_proxy
ALL_PROXY
. I looked at the source of urllib.request.get_env_proxy_for_url and they just lower case it. So it doesn't matter, I guess I'm just used to seeing them together all the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean the case difference. When you write a test, you communicate the expectations of how something is supposed to be used and to work in general. Point is that when you set both http_proxy
and HTTP_PROXY
, this creates a false impression (for any third party reader) and in order for this feature to work, the end-user is supposed to set two env variables with the same value. The underlying implementation you linked implies that the upper-case variant is always preferred and the lower-case is used as a fall-back.
The only reasonable case I see for setting both variables in a test is when the values are different: for example, a test could demonstrate that with http_proxy=http://example.org HTTP_PROXY=http://example.com
set it would choose http://example.com
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. Just doing a little debugging now. Before when I ran the tests I didn't have any environment variables set for the proxies, setting them, then running the tests, the tests fail.
Looks like some other tests break:
FAILED tests/test_helpers.py::test_proxies_from_env[https] - AssertionError: assert dict_keys(['http', 'https']) == {'https'}
FAILED tests/test_helpers.py::test_proxies_from_env[ws] - AssertionError: assert dict_keys(['http', 'ws']) == {'ws'}
FAILED tests/test_helpers.py::test_proxies_from_env[wss] - AssertionError: assert dict_keys(['http', 'wss']) == {'wss'}
FAILED tests/test_helpers.py::test_proxies_from_env_skipped[https] - AssertionError: assert {'http': ProxyInfo(proxy=URL('http://www.example.com,http//proxy.com'), proxy_auth=None)} == {}
FAILED tests/test_helpers.py::test_proxies_from_env_skipped[wss] - AssertionError: assert {'http': ProxyInfo(proxy=URL('http://www.example.com,http//proxy.com'), proxy_auth=None)} == {}
To reproduce:
export http_proxy='http://www.example.com,http://proxy.com'
make test
Should I create an issue for this? I can push a PR after this one to fix it....once I figure it out.
def test_get_env_proxy_for_url(proxy_env_vars, url_input) -> None: | ||
url = URL(url_input) | ||
proxy, proxy_auth = helpers.get_env_proxy_for_url(url) | ||
proxy_list = proxy_env_vars[url.scheme + "_proxy"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, it's best to avoid dynamism like this in tests because it makes it harder to reason about what's expected because one should first dig through several levels of indirection correctly.
But since I don't want an infinite number of reviews on this PR, I'll just accept it. I think it's rather good now.
no_proxy
env var mechanism in the HTTP client
@scirelli could you send a backport PR against the |
PR aio-libs#4445 by @scirelli. Fixes aio-libs#4431. Co-authored-by: Steve Cirelli <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]> (cherry picked from commit 1a4126a)
PR aio-libs#4445 by @scirelli. Fixes aio-libs#4431. Co-authored-by: Steve Cirelli <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]> (cherry picked from commit 1a4126a)
…5556) PR #4445 by @scirelli. Fixes #4431. Co-authored-by: Steve Cirelli <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]> (cherry picked from commit 1a4126a)
PR aio-libs#4445 by @scirelli. Fixes aio-libs#4431. Co-authored-by: Steve Cirelli <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]>
PR aio-libs#4445 by @scirelli. Fixes aio-libs#4431. Co-authored-by: Steve Cirelli <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]>
What do these changes do?
Prior to this patch aiohttp would ignore no_proxy settings.
Are there changes in behavior for the user?
If
no_proxy
orNO_PROXY
is set, and the request host matches one of the hosts from the no_proxy list, no proxy will be used.Need help in finding where the unit tests go for this.
Related issue number
#4431
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.