mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #5681 from mateusduboli/5677
5677: Rebuild proxies on Session#send
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user