Skip to content
Myr

Merge pull request #4356 from nehaljwani/fix-4353

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

Check if host is invalid for proxy

authored by Nate Prewitt · committed by GitHub · parents 234f80a, 9a8a826 · Browse files · 5 files+26 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

5 files+26 added−2 removed

  • tests:+14 added−1 removed
  • other:+12 added−1 removed

5 files+26 added−2 removed

modified:requests/adapters.py+6 added-1 removed
11 unmodified lines
12import socket1314from urllib3.poolmanager import PoolManager, proxy_from_url15from urllib3.response import HTTPResponse16from urllib3.util import parse_url17from urllib3.util import Timeout as TimeoutSauce18from urllib3.util.retry import Retry19from urllib3.exceptions import ClosedPoolError20from urllib3.exceptions import ConnectTimeoutError
13 unmodified lines
34 get_auth_from_url, urldefragauth, select_proxy)35from .structures import CaseInsensitiveDict36from .cookies import extract_cookies_to_jar37from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,37 ProxyError, RetryError, InvalidSchema)38 ProxyError, RetryError, InvalidSchema, InvalidProxyURL)39from .auth import _basic_auth_str4041try:42 from urllib3.contrib.socks import SOCKSProxyManager
257 unmodified lines
300 proxy = select_proxy(url, proxies)301302 if proxy:303 proxy = prepend_scheme_if_needed(proxy, 'http')304 proxy_url = parse_url(proxy)305 if not proxy_url.host:306 raise InvalidProxyURL("Please check proxy URL. It is malformed"307 " and could be missing the host.")308 proxy_manager = self.proxy_manager_for(proxy)309 conn = proxy_manager.connection_from_url(url)310 else:311 # Only scheme should be lower case
219 unmodified lines
modified:requests/exceptions.py+4 added
83 unmodified lines
84class InvalidHeader(RequestException, ValueError):85 """The header value provided was somehow invalid."""868788class InvalidProxyURL(InvalidURL):89 """The proxy URL provided is invalid."""909192class ChunkedEncodingError(RequestException):93 """The server declared chunked encoding but sent an invalid chunk."""9495
31 unmodified lines
modified:tests/test_requests.py+14 added-1 removed
21 unmodified lines
22 cookiejar_from_dict, morsel_to_cookie)23from requests.exceptions import (24 ConnectionError, ConnectTimeout, InvalidSchema, InvalidURL,25 MissingSchema, ReadTimeout, Timeout, RetryError, TooManyRedirects,26 ProxyError, InvalidHeader, UnrewindableBodyError, SSLError)26 ProxyError, InvalidHeader, UnrewindableBodyError, SSLError, InvalidProxyURL)27from requests.models import PreparedRequest28from requests.structures import CaseInsensitiveDict29from requests.sessions import SessionRedirectMixin30from requests.models import urlencode
494 unmodified lines
525 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError526 with pytest.raises(ProxyError):527 requests.get('http://localhost:1', proxies={'http': 'non-resolvable-address'})528529 def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):530 with pytest.raises(InvalidProxyURL):531 requests.get(httpbin_secure(), proxies={'https': 'http:/badproxyurl:3128'})532533 with pytest.raises(InvalidProxyURL):534 requests.get(httpbin(), proxies={'http': 'http://:8080'})535536 with pytest.raises(InvalidProxyURL):537 requests.get(httpbin_secure(), proxies={'https': 'https://'})538539 with pytest.raises(InvalidProxyURL):540 requests.get(httpbin(), proxies={'http': 'http:///example.com:8080'})541542 def test_basicauth_with_netrc(self, httpbin):543 auth = ('user', 'pass')544 wrong_auth = ('wronguser', 'wrongpass')545 url = httpbin('basic-auth', 'user', 'pass')
1895 unmodified lines
modified:AUTHORS.rst+1 added
178 unmodified lines
179- Ed Morley (`@edmorley <https://github.com/edmorley>`_)180- Matt Liu <liumatt@gmail.com> (`@mlcrazy <https://github.com/mlcrazy>`_)181- Taylor Hoff <primdevs@protonmail.com> (`@PrimordialHelios <https://github.com/PrimordialHelios>`_)182- Arthur Vigil (`@ahvigil <https://github.com/ahvigil>`_)183- Nehal J Wani (`@nehaljwani <https://github.com/nehaljwani>`_)
modified:HISTORY.rst+1 added
7 unmodified lines
89**Improvements**1011- Warn user about possible slowdown when using cryptography version < 1.3.412- Check for invalid host in proxy URL, before forwarding request to adapter.1314**Bugfixes**1516- Parsing empty ``Link`` headers with ``parse_header_links()`` no longer return one bogus entry
1526 unmodified lines