Skip to content
Myr

Merge branch 'fix_401_cookies' of git://github.com/sigmavirus24/requests into 2.0

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 · parents f865d61, 286ddb6 · Browse files · 3 files+28 added−8 removed
This commit

State

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

Diff stats

3 files+28 added−8 removed

  • other:+28 added−8 removed

3 files+28 added−8 removed

modified:requests/auth.py+6 added-3 removed
16 unmodified lines
1718from .compat import urlparse, str19from .utils import parse_dict_header202121log = logging.getLogger(__name__)2223CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'24CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
132 unmodified lines
157 # Consume content and release the original connection158 # to allow our new request to reuse the same one.159 r.content160 r.raw.release_conn()161 prep = r.request.copy()162 prep.prepare_cookies(r.cookies)163163 r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)164 _r = r.connection.send(r.request, **kwargs)164 prep.headers['Authorization'] = self.build_digest_header(165 prep.method, prep.url)166 _r = r.connection.send(prep, **kwargs)167 _r.history.append(r)168 _r.request = prep169170 return _r171172 setattr(self, 'num_401_calls', 1)
8 unmodified lines
modified:requests/sessions.py+5 added-4 removed
72 unmodified lines
73 i = 07475 # ((resp.status_code is codes.see_other))76 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):77 prepared_request = PreparedRequest()78 prepared_request.body = req.body79 prepared_request.headers = req.headers.copy()80 prepared_request.hooks = req.hooks77 prepared_request = req.copy()7879 resp.content # Consume socket so it can be released8081 if i >= self.max_redirects:
382 unmodified lines
464 # Response manipulation hooks465 r = dispatch_hook('response', hooks, r, **kwargs)466467 # Persist cookies468 if r.history:469 # If the hooks create history then we want those cookies too470 for resp in r.history:471 extract_cookies_to_jar(self.cookies, resp.request, resp.raw)472 extract_cookies_to_jar(self.cookies, request, r.raw)473474 # Redirect resolving generator.475 gen = self.resolve_redirects(r, request, stream=stream,
52 unmodified lines
modified:test_requests.py+17 added-1 removed
265 unmodified lines
266 r = requests.get(url)267 self.assertEqual(r.status_code, 401)268269 s = requests.session()270 s.auth = auth270 s.auth = HTTPDigestAuth('user', 'pass')271 r = s.get(url)272 self.assertEqual(r.status_code, 200)273274 def test_DIGEST_AUTH_RETURNS_COOKIE(self):275 url = httpbin('digest-auth', 'auth', 'user', 'pass')276 auth = HTTPDigestAuth('user', 'pass')277 r = requests.get(url)278 assert r.cookies['fake'] == 'fake_value'279280 r = requests.get(url, auth=auth)281 assert r.status_code == 200282283 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self):284 url = httpbin('digest-auth', 'auth', 'user', 'pass')285 auth = HTTPDigestAuth('user', 'pass')286 s = requests.Session()287 s.get(url, auth=auth)288 assert s.cookies['fake'] == 'fake_value'289290 def test_DIGEST_STREAM(self):291292 auth = HTTPDigestAuth('user', 'pass')293 url = httpbin('digest-auth', 'auth', 'user', 'pass')
519 unmodified lines