Skip to content
Myr

Port bpo-39057 to Requests (#7427)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by GitHub · parent 3816cfa · Browse files · 2 files+27 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−2 removed

  • tests:+23 added−0 removed
  • other:+4 added−2 removed

2 files+27 added−2 removed

modified:src/requests/utils.py+4 added-2 removed
849 unmodified lines
850 if parsed.port:851 host_with_port += f":{parsed.port}"852853 for host in no_proxy_hosts:854 host = host.lstrip(".")855 if hostname == host or host_with_port == host:856 return True857 host = "." + host858 if hostname.endswith(host) or host_with_port.endswith(host):855 # The URL does match something in no_proxy, so we don't want856 # to apply the proxies on this URL.859 return True860861 with set_environ("no_proxy", no_proxy_arg):862 try:
293 unmodified lines
modified:tests/test_utils.py+23 added
842 unmodified lines
843 # Test 'no_proxy' argument844 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected845846847@pytest.mark.parametrize(848 "url, expected",849 (850 ("http://localhost/", True),851 ("http://anotherdomain.com:8888/", True),852 ("http://newdomain.com:1234/", True),853 ("http://www.newdomain.com:1234/", True),854 ("http://foo.d.o.t/", True),855 ("http://d.o.t/", True),856 ("http://prelocalhost/", False),857 ("http://newdomain.com/", False),858 ("http://newdomain.com:1235/", False),859 ),860)861def test_should_bypass_proxies_no_proxy_domain_boundary(url, expected):862 """Ensure no_proxy matching respects domain boundaries and does not863 greedily match domains that merely endswith the no_proxy entry.864 See CPython bpo-39057.865 """866 no_proxy = "localhost, anotherdomain.com, newdomain.com:1234, .d.o.t"867 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected868869870@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")871@pytest.mark.parametrize(872 "url, expected, override",873 (
140 unmodified lines