Commit a784de5
committed
Fix: Respect no_proxy in proxies dictionary and NO_PROXY env var
This commit addresses issue #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 #50001 parent 7029833 commit a784de5
File tree
4 files changed
+102
-0
lines changed- src/requests
- tests
4 files changed
+102
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
699 | 699 | | |
700 | 700 | | |
701 | 701 | | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
702 | 708 | | |
703 | 709 | | |
704 | 710 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
839 | 843 | | |
840 | 844 | | |
841 | 845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1997 | 1997 | | |
1998 | 1998 | | |
1999 | 1999 | | |
| 2000 | + | |
2000 | 2001 | | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
2001 | 2065 | | |
2002 | 2066 | | |
2003 | 2067 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
975 | 975 | | |
976 | 976 | | |
977 | 977 | | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
0 commit comments