Conversation
ed6f3a0 to
a784de5
Compare
|
The Also, select_proxy now returns None when NO_PROXY matches — callers of select_proxy should be checked to ensure they handle None gracefully (currently merge_environment_settings and send both use the return value as a dict key or proxy URL). Fix the broken test and this should be good. |
|
Thank you for the review. I have addressed the issues raised:
|
This commit addresses issue psf#5000 by ensuring that the `no_proxy` directive is respected, whether it's provided directly within the `proxies` dictionary passed to request functions or set as the `NO_PROXY` environment variable. Previously, `no_proxy` in the `proxies` dictionary was not fully honored, and the `NO_PROXY` environment variable was not always checked when a `proxies` dictionary was provided. This change includes: 1. **`src/requests/sessions.py`**: Modified the `Session.send` method to check the `no_proxy` key within the `kwargs['proxies']` dictionary. If the request URL matches any pattern in the `no_proxy` list, the proxies are cleared for that request. 2. **`src/requests/utils.py`**: Updated the `select_proxy` function to check the `NO_PROXY` environment variable using `should_bypass_proxies` before selecting a proxy from the provided `proxies` dictionary. 3. **`tests/test_requests.py`**: Added new test cases (`test_no_proxy_in_proxies_dict`, `test_no_proxy_star_in_proxies_dict`, `test_no_proxy_not_matching_in_proxies_dict`) to verify that `no_proxy` within the `proxies` dictionary works as expected, using mocks to check if the proxy is bypassed. 4. **`tests/test_utils.py`**: Added new test cases (`test_select_proxy_with_no_proxy`) to ensure the `NO_PROXY` environment variable is correctly handled by `select_proxy`. These changes ensure consistent behavior for proxy bypass logic, regardless of how the proxy settings are configured. Closes psf#5000
…x test arrangement - Support both `no_proxy` and `no` keys in the `proxies` dictionary for bypass rules in `Session.send`, `merge_environment_settings`, and `resolve_proxies`, ensuring compatibility with `urllib` expectations. - Update `select_proxy` to check bypass rules before selecting a proxy. - Ensure `select_proxy` respects standard precedence for environment variables (preferring lowercase `no_proxy` over `NO_PROXY`). - Clear proxies in `Session.send` if bypass rules are met for the requested URL. - Restore `test_rewind_body_no_seek` to its original implementation with `BadFileObj` and `UnrewindableBodyError` assertion. - Move new proxy bypass tests (`test_no_proxy_in_proxies_dict`, etc.) to be standalone tests rather than nested inside `test_rewind_body_no_seek`.
- Update docstrings for `requests.request` and `Session.request` to mention that the `proxies` dictionary can include a `'no'` or `'no_proxy'` key to specify URLs that should bypass proxy settings.
7524091 to
508449a
Compare
|
rebased onto orgin's main |
This PR addresses issue #5000 by ensuring that proxy bypass directives are respected, whether provided directly within the
proxiesdictionary passed to request functions or set via environment variables.Previously, bypass rules in the
proxiesdictionary were not fully honored, and theNO_PROXYenvironment variable was not always checked when aproxiesdictionary was provided.This change includes:
src/requests/sessions.py:Session.sendto check bothno_proxyandnokeys in theproxiesdictionary. If the request URL matches any pattern in the list, proxies are cleared for that request.merge_environment_settingsto check bothno_proxyandnokeys when merging environment proxies.Session.requestdocstring to clarifynoandno_proxykey support.src/requests/utils.py:select_proxyto evaluate bypass rules before selecting a proxy.select_proxyto respect standard precedence for environment variables (preferring lowercaseno_proxyoverNO_PROXY).resolve_proxiesto check bothno_proxyandnokeys.src/requests/api.py:requests.requestdocstring to clarifynoandno_proxykey support in theproxiesdictionary.tests/test_requests.py:test_no_proxy_in_proxies_dict,test_no_proxy_star_in_proxies_dict,test_no_proxy_not_matching_in_proxies_dict) to verify that bypass rules within theproxiesdictionary work as expected.tests/test_utils.py:test_select_proxy_with_no_proxy) to ensure proxy bypass rules and environment variables are correctly handled byselect_proxy.These changes ensure consistent behavior for proxy bypass logic, regardless of how the proxy settings are configured.
Closes #5000