Skip to content
Myr

#5677: Rebuild proxies on Session#send

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

authored by Mateus Dubiela Oliveira · committed by Mateus Dubiela Oliveira · parent 589c454 · Browse files · 2 files+40 added−1 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+40 added−1 removed

  • tests:+39 added−0 removed
  • other:+1 added−1 removed

2 files+40 added−1 removed

modified:requests/sessions.py+1 added-1 removed
631 unmodified lines
632 # the correct parameters to reproduce the previous request.633 kwargs.setdefault('stream', self.stream)634 kwargs.setdefault('verify', self.verify)635 kwargs.setdefault('cert', self.cert)636 kwargs.setdefault('proxies', self.proxies)636 kwargs.setdefault('proxies', self.rebuild_proxies(request, self.proxies))637638 # It's possible that users might accidentally send a Request object.639 # Guard against that specific failure case.640 if isinstance(request, Request):
141 unmodified lines
modified:tests/test_requests.py+39 added
38 unmodified lines
39# Requests to this URL should always fail with a connection timeout (nothing40# listening on that port)41TARPIT = 'http://10.255.255.1'4243# This is to avoid waiting the timeout of using TARPIT44INVALID_PROXY='http://localhost:1'4546try:47 from ssl import SSLContext48 del SSLContext49 HAS_MODERN_SSL = True
503 unmodified lines
553554 with pytest.raises(InvalidProxyURL):555 requests.get(httpbin(), proxies={'http': 'http:///example.com:8080'})556557 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):558 with override_environ(http_proxy=INVALID_PROXY):559 with pytest.raises(ProxyError):560 session = requests.Session()561 request = requests.Request('GET', httpbin())562 session.send(request.prepare())563564 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):565 with override_environ(http_proxy=INVALID_PROXY):566 with pytest.raises(ProxyError):567 session = requests.Session()568 request = requests.Request('GET', httpbin())569 prepared = session.prepare_request(request)570 session.send(prepared)571572 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):573 with override_environ(http_proxy=INVALID_PROXY):574 with pytest.raises(ProxyError):575 session = requests.Session()576 url = httpbin('redirect/1')577 print(url)578 request = requests.Request('GET', url)579 session.send(request.prepare())580581 def test_respect_proxy_env_on_get(self, httpbin):582 with override_environ(http_proxy=INVALID_PROXY):583 with pytest.raises(ProxyError):584 session = requests.Session()585 session.get(httpbin())586587 def test_respect_proxy_env_on_request(self, httpbin):588 with override_environ(http_proxy=INVALID_PROXY):589 with pytest.raises(ProxyError):590 session = requests.Session()591 session.request(method='GET', url=httpbin())592593 def test_basicauth_with_netrc(self, httpbin):594 auth = ('user', 'pass')595 wrong_auth = ('wronguser', 'wrongpass')596 url = httpbin('basic-auth', 'user', 'pass')
1972 unmodified lines