proxy manager
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent c3431bb · Browse files · 2 files·+16 added−3 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+16 added−3 removed
- other:+16 added−3 removed
Provenance
- Commit
a982b0d- Tree
b235936- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
c3431bb
2 files changed+16 added−3 removed
modified:requests/adapters.py+1 added-1 removed
125 unmodified lines126 proxies = proxies or {}127 proxy = proxies.get(urlparse(url).scheme)128 129 if proxy:130- conn = poolmanager.proxy_from_url(proxy)130+ conn = self.poolmanager.ProxyManager(self.poolmanager.proxy_from_url(proxy))131 else:132 conn = self.poolmanager.connection_from_url(url)133 134 return conn52 unmodified linesmodified:requests/sessions.py+15 added-2 removed
17 unmodified lines18 19 from .compat import urlparse, urljoin20 from .adapters import HTTPAdapter21 22-from .utils import requote_uri22+from .utils import requote_uri, get_environ_proxies, get_netrc_auth23 24 from .status_codes import codes25 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)26 DEFAULT_REDIRECT_LIMIT = 30176 unmodified lines203 verify=None,204 cert=None):205 206 cookies = cookies or {}207+ proxies = proxies or {}208 209 # Bootstrap CookieJar.210 if not isinstance(cookies, cookielib.CookieJar):211 cookies = cookiejar_from_dict(cookies)1 unmodified line213 # Bubble down session cookies.214 for cookie in self.cookies:215 cookies.set_cookie(cookie)216 217+ # Gather clues from the surrounding environment.218+ if self.trust_env:219+ # Set environment's proxies.220+ env_proxies = get_environ_proxies(url) or {}221+ for (k, v) in env_proxies.items():222+ proxies.setdefault(k, v)223+224+ # Set environment's basic authentication.225+ if not auth:226+ auth = get_netrc_auth(url)227+228 # Merge all the kwargs.229 params = merge_kwargs(params, self.params)230 headers = merge_kwargs(headers, self.headers)231 auth = merge_kwargs(auth, self.auth)2 unmodified lines234 stream = merge_kwargs(stream, self.stream)235 verify = merge_kwargs(verify, self.verify)236 cert = merge_kwargs(cert, self.cert)237 238+239 # Create the Request.240 req = Request()241 req.method = method242 req.url = url8 unmodified lines251 # Prepare the Request.252 prep = req.prepare()253 254 # Send the request.242- resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert)255+ resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)256 257 # Redirect resolving generator.258 gen = self.resolve_redirects(resp, req, stream, timeout, verify, cert)259 115 unmodified lines