Merge pull request #5681 from mateusduboli/5677

5677: Rebuild proxies on Session#send
This commit is contained in:
Ian Stapleton Cordasco
2021-01-24 16:59:46 -06:00
committed by GitHub
2 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -633,7 +633,7 @@ class Session(SessionRedirectMixin):
kwargs.setdefault('stream', self.stream)
kwargs.setdefault('verify', self.verify)
kwargs.setdefault('cert', self.cert)
kwargs.setdefault('proxies', self.proxies)
kwargs.setdefault('proxies', self.rebuild_proxies(request, self.proxies))
# It's possible that users might accidentally send a Request object.
# Guard against that specific failure case.
+39
View File
@@ -40,6 +40,9 @@ from urllib3.util import Timeout as Urllib3Timeout
# listening on that port)
TARPIT = 'http://10.255.255.1'
# This is to avoid waiting the timeout of using TARPIT
INVALID_PROXY='http://localhost:1'
try:
from ssl import SSLContext
del SSLContext
@@ -551,6 +554,42 @@ class TestRequests:
with pytest.raises(InvalidProxyURL):
requests.get(httpbin(), proxies={'http': 'http:///example.com:8080'})
def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):
with override_environ(http_proxy=INVALID_PROXY):
with pytest.raises(ProxyError):
session = requests.Session()
request = requests.Request('GET', httpbin())
session.send(request.prepare())
def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):
with override_environ(http_proxy=INVALID_PROXY):
with pytest.raises(ProxyError):
session = requests.Session()
request = requests.Request('GET', httpbin())
prepared = session.prepare_request(request)
session.send(prepared)
def test_respect_proxy_env_on_send_with_redirects(self, httpbin):
with override_environ(http_proxy=INVALID_PROXY):
with pytest.raises(ProxyError):
session = requests.Session()
url = httpbin('redirect/1')
print(url)
request = requests.Request('GET', url)
session.send(request.prepare())
def test_respect_proxy_env_on_get(self, httpbin):
with override_environ(http_proxy=INVALID_PROXY):
with pytest.raises(ProxyError):
session = requests.Session()
session.get(httpbin())
def test_respect_proxy_env_on_request(self, httpbin):
with override_environ(http_proxy=INVALID_PROXY):
with pytest.raises(ProxyError):
session = requests.Session()
session.request(method='GET', url=httpbin())
def test_basicauth_with_netrc(self, httpbin):
auth = ('user', 'pass')
wrong_auth = ('wronguser', 'wrongpass')