-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
improve proxy bypass on Windows #3979
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3979 +/- ##
==========================================
- Coverage 89.76% 89.74% -0.03%
==========================================
Files 15 15
Lines 1955 1940 -15
==========================================
- Hits 1755 1741 -14
+ Misses 200 199 -1
Continue to review full report at Codecov.
|
|
As first step I added tests to check the current behavior (they take around 30 seconds to run on my system) so we can detect regressions in the new implementation. Tested with Python 2.7 and 3.5. |
|
Well coverage drops obviously as these tests are only run on Windows :-/ From my POV this is ready to get merged, please review. |
Lukasa
left a comment
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.
Hrm, we may need to enable appveyor to ensure that this stuff actually works.
requests/utils.py
Outdated
| 'ProxyEnable')[0] | ||
| proxyOverride = str(winreg.QueryValueEx(internetSettings, | ||
| 'ProxyOverride')[0]) | ||
| # ^^^^ Returned as Unicode but problems if not converted to ASCII |
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.
This comment is confusing: what is it trying to say?
requests/utils.py
Outdated
| for val in host: | ||
| if re.match(test, val, re.I): | ||
| return 1 | ||
| return 0 |
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.
We may as well just use booleans.
requests/utils.py
Outdated
|
|
||
| # try to make a host list from name and IP address. | ||
| rawHost, port = splitport(host) | ||
| host = [rawHost] |
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.
What is this for?
| # canonical entry. | ||
| proxyOverride = proxyOverride.split(';') | ||
| # now check if we match one of the registry values. | ||
| for test in proxyOverride: |
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.
We can probably unify these two lines.
| if compat.is_py3: | ||
| import winreg | ||
| else: | ||
| import _winreg as winreg |
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.
May as well just import this directly from compat.
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.
Then we would need a platform check in compat and winreg could be None on non Windows platforms...
|
The code is copy pasted from Python 3.5's urlib/request.py with the lines doing DNS lookups (and appending to |
|
I'm a bit disinclined to do that unless we think this is going to be temporary code (which it won't be until we drop 2.7 support at least). If we are going to support it I'd like the code to be sensible and comprehensible. 😃 |
|
@Lukasa Please give me a note when AppVeyor tests are working. Then I'll udpate this PR. |
|
@schlamar Yeah, might be worth doing. |
7d563d4 to
db57972
Compare
|
close/reopened to get appveyor to re-run |
|
It'll need to be rebased on top of master. |
nateprewitt
left a comment
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.
This looks like a good start @schlamar! I left a couple notes with some outstanding questions from my end. A couple are just stylistic nits but the others are on functionality.
requests/utils.py
Outdated
| for test in proxyOverride: | ||
| if test == '<local>': | ||
| if '.' not in host: | ||
| return 1 |
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.
Is there a reason this is 1 and not True like the other return values? If so, we should probably add a comment explaining why.
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.
Nope, I forgot this one 🙈
requests/compat.py
Outdated
|
|
||
| if is_py2: | ||
| from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass | ||
| from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass, \ |
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.
It may be better to follow something closer to the import convention of the other modules, rather than use \.
from urllib import (
quote, unquote, quote_plus, unquote_plus, urlencode, getproxies,
proxy_bypass, proxy_bypass_environment, getproxies_environment)
requests/utils.py
Outdated
| Returns settings gathered from the environment, if specified, | ||
| or the registry. | ||
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.
Could we remove this extra line here.
| if getproxies_environment(): | ||
| return proxy_bypass_environment(host) | ||
| else: | ||
| return proxy_bypass_registry(host) |
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.
This seems to return a boolean but the docstring states it returns a dictionary of scheme to proxy mappings. It may be a good idea to clarify this case.
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.
Somehow I copied the wrong docstring, I'll fix this :)
|
@Lukasa @nateprewitt Updated, please review again. |
|
@schlamar Based on codecov's output the actual reason you're reducing coverage is that the diff isn't covered enough to avoid regressing it. To match coverage you'd need to cover 90% of the diff, but only 86% is covered. You can see the lines we're missing here: what are the odds that we can write tests that appropriately cover them? |
Lukasa
left a comment
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.
Cool, so this is looking really good! I'd love to see if we can get the test coverage up a bit higher, and I've left a note in the diff. 😄
requests/utils.py
Outdated
| DEFAULT_CA_BUNDLE_PATH = certs.where() | ||
|
|
||
|
|
||
| if os.name == 'nt': |
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.
Rather than use os.name, might it be better to use platform.system?
requests/utils.py
Outdated
| import _winreg as winreg | ||
|
|
||
| except ImportError: | ||
| # Std modules, so should be around - but you never know! |
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.
@Lukasa Should I remove this one, I don't think this is really necessary...
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.
Yeah, let's do that: there's no need to tolerate this ImportError I don't think.
|
@Lukasa Updated, please review again :) |
Lukasa
left a comment
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.
Ok, I think I'm happy. Time to see what @nateprewitt thinks.
nateprewitt
left a comment
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.
Looks good to me!
Lukasa
left a comment
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.
Ok then, one last request. Can you add notes to the changelog to note that a) we've changed our strategy for looking up proxy bypass information on Windows, and b) we've removed the proxy bypass cache as it's no longer needed? Just want to make sure we have a good reference in case these things have unforseen bugs, and I bet I'll forget that there were two things in this PR when it comes to writing the changelog later. 😁
|
When was the proxy bypass cache introduced? I'd like to make a reference but can't find anything in the changelog :) |
|
Ah yes, this wasn't even released yet. @Lukasa in this case I would ignore this?! |
|
Yeah, you would. =) |
Lukasa
left a comment
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.
Alright, let's do it!
|
🎉 |
See #3976