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
urllib.request no_proxy check differs from curl #71051
Comments
The no_proxy environment variable works in python as a case Curl handles this variable as a case insensitive hostname check. Case sensitivity appears to be in conflict with the DNS Case While the suffix check is documented I believe the ideal solution would be to have proxy_bypass be a |
No, urllib.request does not handle the no_proxy environment in case-sensitive way. It first checks if any environment_variable.lower() ends with "_proxy", and then checks if there is any environment_variable ends with "_proxy". So it works as a case insensitive check, but the lowercase one will override others, e.g, no_proxy overrides no_PROXY. But the document is misleading, it should be clarified. |
I believe there was a misunderstanding. While the environment variable name is handled in a case Please see some examples below: >>> os.environ['no_proxy'] = 'example.com'
>>> urllib.request.proxy_bypass('EXAMPLE.com')
0
>>> urllib.request.proxy_bypass('example.com')
1 Also to clarify the meaning of suffix check: >>> os.environ['no_proxy'] = 'example.com'
>>> urllib.request.proxy_bypass('myexample.com')
1 My apologies for my lack of clarity. |
Ohh, it's my fault to misunderstand. I think your thinking is reasonable. Curl handles the suffix check insensitively. |
I write a patch to fix this. It seems on Windows and MacOS the behaviour is right. On MacOS it leaves the matching to fnmatch. On Windows it uses case insensitive regular matching. |
The code has changed recently. I update the patch to reveal the change. |
I think this patch looks okay. It fixes the case insensitivity problem, but there is also the string suffix problem (see the myexample.com demo). I think it is reasonable for example.com to match my.example.com, but not myexample.com. |
Yes, you are right. I don't notice that. I will try to fix it. |
I update the patch to use regular expression to handle both case and suffix. This regular expression has the function of curl's check_noproxy. And I think a separate test case is better here. |
Update to improve the test case. |
Thanks for your comment martin. Using re.escape is really a good advise. |
This version looks okay to me, thanks. |
New changeset ca882ee68d46 by Martin Panter in branch '3.5': New changeset 1ceb91974dc4 by Martin Panter in branch 'default': New changeset a1aad42f1195 by Martin Panter in branch '2.7': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: