digest works!
Before adoption: this commit came in with the history the project adopted, so no landing records it.
added some nice backwards compatible stuff too
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 1c30ef4 · Browse files · 4 files·+12 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+12 added−13 removed
- other:+12 added−13 removed
Provenance
- Commit
4837900- Tree
44655c8- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
1c30ef4
4 files changed+12 added−13 removed
modified:requests/adapters.py+9 added-2 removed
11 unmodified lines12 import socket13 14 from .models import Response15 from .packages.urllib3.poolmanager import PoolManager16+from .hooks import dispatch_hook17 from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers18 from .structures import CaseInsensitiveDict19 from .packages.urllib3.exceptions import MaxRetryError20 from .packages.urllib3.exceptions import TimeoutError67 unmodified lines88 conn.key_file = cert[1]89 else:90 conn.cert_file = cert91 91- @staticmethod92- def build_response(req, resp):92+ # @staticmethod93+ def build_response(self, req, resp):94 response = Response()95 96 # Fallback to None if there's no status_code, for whatever reason.97 response.status_code = getattr(resp, 'status', None)12 unmodified lines110 111 # Add new cookies from the server.112 extract_cookies_to_jar(response.cookies, req, resp)113 114+ # Give the Response some context.115+ response.request = req116+ response.connection = self117+118+ # Run the Response hook.119+ response = dispatch_hook('response', req.hooks, response)120 return response121 122 123 def close(self):48 unmodified linesmodified:requests/auth.py+1 added-3 removed
139 unmodified lines140 def handle_401(self, r):141 """Takes the given response and tries digest-auth, if needed."""142 143 num_401_calls = r.request.hooks['response'].count(self.handle_401)144-144 s_auth = r.headers.get('www-authenticate', '')145 146 if 'digest' in s_auth.lower() and num_401_calls < 2:147 4 unmodified lines152 r.content153 r.raw.release_conn()154 155 r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)157- r.request.send(anyway=True)158- _r = r.request.response156+ _r = r.connection.send(r.request)157 _r.history.append(r)158 159 return _r160 8 unmodified linesmodified:requests/models.py+1 added-7 removed
144 unmodified lines145 146 class RequestHooksMixin(object):147 def register_hook(self, event, hook):148 """Properly register a hook."""149- print self150- print event151- print hook149+150 if isinstance(hook, collections.Callable):151 self.hooks[event].append(hook)152 elif hasattr(hook, '__iter__'):153 self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable))185 unmodified lines339 340 def prepare_auth(self, auth):341 """Prepares the given HTTP auth data."""342 if auth:345- # print auth343 if isinstance(auth, tuple) and len(auth) == 2:344 # special-case basic HTTP auth345 auth = HTTPBasicAuth(*auth)346 347 # Allow auth to make its changes.348 r = auth(self)352- # print r353- # print r.__dict__354- # print self.__dict__349 350 # Update self to reflect the auth changes.351 self.__dict__.update(r.__dict__)352 249 unmodified linesmodified:requests/sessions.py+1 added-1 removed
10 unmodified lines11 12 from .compat import cookielib13 from .cookies import cookiejar_from_dict, remove_cookie_by_name14 from .models import Request15-from .hooks import dispatch_hook15+from .hooks import dispatch_hook, HOOKS16 from .utils import header_expand, from_key_val_list, default_headers17 from .exceptions import TooManyRedirects18 19 from .compat import urlparse, urljoin331 unmodified lines