Add support for SOCKS
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Cory Benfield · committed by Cory Benfield · parent 396963a · Browse files · 1 file·+33 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+33 added−10 removed
- other:+33 added−10 removed
Provenance
- Commit
08364c6- Tree
e28ff02- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
396963a
1 file changed+33 added−10 removed
modified:requests/adapters.py+33 added-10 removed
31 unmodified lines32 from .packages.urllib3.exceptions import SSLError as _SSLError33 from .packages.urllib3.exceptions import ResponseError34 from .cookies import extract_cookies_to_jar35 from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,36- ProxyError, RetryError)36+ ProxyError, RetryError, InvalidSchema)37 from .auth import _basic_auth_str38 39+try:40+ from .packages.urllib3.contrib.socks import SOCKSProxyManager41+except ImportError:42+ def SOCKSProxyManager(*args, **kwargs):43+ raise InvalidSchema("Missing dependencies for SOCKS support.")44+45 DEFAULT_POOLBLOCK = False46 DEFAULT_POOLSIZE = 1047 DEFAULT_RETRIES = 048 DEFAULT_POOL_TIMEOUT = None106 unmodified lines155 :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.156 :returns: ProxyManager157 """158 if not proxy in self.proxy_manager:159+ if proxy.lower().startswith('socks'):160+ username, password = get_auth_from_url(proxy)161+ self.proxy_manager[proxy] = SOCKSProxyManager(162+ proxy,163+ username=username,164+ password=password,165+ num_pools=self._pool_connections,166+ maxsize=self._pool_maxsize,167+ block=self._pool_block,168+ **proxy_kwargs169+ )170+ else:153- proxy_headers = self.proxy_headers(proxy)154- self.proxy_manager[proxy] = proxy_from_url(155- proxy,156- proxy_headers=proxy_headers,157- num_pools=self._pool_connections,158- maxsize=self._pool_maxsize,159- block=self._pool_block,160- **proxy_kwargs)171+ proxy_headers = self.proxy_headers(proxy)172+ self.proxy_manager[proxy] = proxy_from_url(173+ proxy,174+ proxy_headers=proxy_headers,175+ num_pools=self._pool_connections,176+ maxsize=self._pool_maxsize,177+ block=self._pool_block,178+ **proxy_kwargs)179 180 return self.proxy_manager[proxy]181 182 def cert_verify(self, conn, url, verify, cert):118 unmodified lines301 :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.302 """303 proxy = select_proxy(request.url, proxies)304 scheme = urlparse(request.url).scheme305+ proxy_scheme = urlparse(proxy).scheme306+307+ if proxy and proxy_scheme.lower().startswith('socks'):308+ # Socks proxies behave like the proxy isn't there at all.309+ url = request.path_url287- if proxy and scheme != 'https':310+ elif proxy and scheme != 'https':311 url = urldefragauth(request.url)312 else:313 url = request.path_url314 162 unmodified lines