Skip to content
Myr

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

4 files+12 added−13 removed

modified:requests/adapters.py+9 added-2 removed
11 unmodified lines
12import socket1314from .models import Response15from .packages.urllib3.poolmanager import PoolManager16from .hooks import dispatch_hook17from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers18from .structures import CaseInsensitiveDict19from .packages.urllib3.exceptions import MaxRetryError20from .packages.urllib3.exceptions import TimeoutError
67 unmodified lines
88 conn.key_file = cert[1]89 else:90 conn.cert_file = cert9191 @staticmethod92 def build_response(req, resp):92 # @staticmethod93 def build_response(self, req, resp):94 response = Response()9596 # Fallback to None if there's no status_code, for whatever reason.97 response.status_code = getattr(resp, 'status', None)
12 unmodified lines
110111 # Add new cookies from the server.112 extract_cookies_to_jar(response.cookies, req, resp)113114 # Give the Response some context.115 response.request = req116 response.connection = self117118 # Run the Response hook.119 response = dispatch_hook('response', req.hooks, response)120 return response121122123 def close(self):
48 unmodified lines
modified:requests/auth.py+1 added-3 removed
139 unmodified lines
140 def handle_401(self, r):141 """Takes the given response and tries digest-auth, if needed."""142143 num_401_calls = r.request.hooks['response'].count(self.handle_401)144144 s_auth = r.headers.get('www-authenticate', '')145146 if 'digest' in s_auth.lower() and num_401_calls < 2:147
4 unmodified lines
152 r.content153 r.raw.release_conn()154155 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)158159 return _r160
8 unmodified lines
modified:requests/models.py+1 added-7 removed
144 unmodified lines
145146class RequestHooksMixin(object):147 def register_hook(self, event, hook):148 """Properly register a hook."""149 print self150 print event151 print hook149150 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 lines
339340 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)346347 # Allow auth to make its changes.348 r = auth(self)352 # print r353 # print r.__dict__354 # print self.__dict__349350 # Update self to reflect the auth changes.351 self.__dict__.update(r.__dict__)352
249 unmodified lines
modified:requests/sessions.py+1 added-1 removed
10 unmodified lines
1112from .compat import cookielib13from .cookies import cookiejar_from_dict, remove_cookie_by_name14from .models import Request15from .hooks import dispatch_hook15from .hooks import dispatch_hook, HOOKS16from .utils import header_expand, from_key_val_list, default_headers17from .exceptions import TooManyRedirects1819from .compat import urlparse, urljoin
331 unmodified lines