Skip to content
Myr

Fixed logic for auto redirect in GET and HEAD methods.

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

authored by verm666 · committed by Kenneth Reitz · parent 6d25fff · Browse files · 3 files+14 added−2 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+14 added−2 removed

  • other:+14 added−2 removed

3 files+14 added−2 removed

modified:requests/api.py+6 added
93 unmodified lines
94 :param url: URL for the new :class:`Request` object.95 :param **kwargs: Optional arguments that ``request`` takes.96 """9798 if "allow_redirects" not in kwargs:99 kwargs["allow_redirects"] = True100101 return request('get', url, **kwargs)102103104def head(url, **kwargs):
2 unmodified lines
107 :param url: URL for the new :class:`Request` object.108 :param **kwargs: Optional arguments that ``request`` takes.109 """110111 if "allow_redirects" not in kwargs:112 kwargs["allow_redirects"] = True113114 return request('head', url, **kwargs)115116117def post(url, data='', **kwargs):
40 unmodified lines
modified:requests/models.py+1 added-2 removed
210 unmodified lines
211 if r.status_code in REDIRECT_STATI and not self.redirect:212213 while (214 ('location' in r.headers) and215 ((self.method in ('GET', 'HEAD')) or216 (r.status_code is codes.see_other) or215 ((r.status_code is codes.see_other) or216 (self.allow_redirects))217 ):218219 r.fo.close()
426 unmodified lines
modified:test_requests.py+7 added
58 unmodified lines
59 def test_HTTP_200_OK_GET(self):60 r = requests.get(httpbin('/'))61 self.assertEqual(r.status_code, 200)6263 def test_HTTP_302_ALLOW_REDIRECT_GET(self):64 r = requests.get(httpbin('redirect', '1'))65 self.assertEqual(r.status_code, 200)6667 def test_HTTP_302_GET(self):68 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)69 self.assertEqual(r.status_code, 302)7071 def test_HTTPS_200_OK_GET(self):72 r = requests.get(httpsbin('/'))73 self.assertEqual(r.status_code, 200)74
408 unmodified lines