Skip to content
Myr

Make get and head requests respect allow_redirects=False.

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

authored by Daniel Miller · committed by Daniel Miller · parent 8b64097 · Browse files · 3 files+23 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

3 files+23 added−3 removed

  • other:+23 added−3 removed

3 files+23 added−3 removed

modified:requests/api.py+4 added
88 unmodified lines
89 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.90 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.91 :param auth: (optional) AuthObject to enable Basic HTTP Auth.92 :param timeout: (optional) Float describing the timeout of the request.93 :param allow_redirects: (optional) Boolean. Set to False to disable redirect following.94 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.95 """9697 kwargs.setdefault('allow_redirects', True)98 return request('GET', url, **kwargs)99100101def head(url, **kwargs):
5 unmodified lines
107 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.108 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.109 :param auth: (optional) AuthObject to enable Basic HTTP Auth.110 :param timeout: (optional) Float describing the timeout of the request.111 :param allow_redirects: (optional) Boolean. Set to False to disable redirect following.112 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.113 """114115 kwargs.setdefault('allow_redirects', True)116 return request('HEAD', url, **kwargs)117118119def post(url, data='', **kwargs):
69 unmodified lines
modified:requests/models.py+1 added-3 removed
201 unmodified lines
202 if r.status_code in REDIRECT_STATI and not self.redirect:203204 while (205 ('location' in r.headers) and206 ((self.method in ('GET', 'HEAD')) or207 (r.status_code is codes.see_other) or208 (self.allow_redirects))206 ((r.status_code is codes.see_other) or (self.allow_redirects))207 ):208209 r.close()210
411 unmodified lines
modified:test_requests.py+18 added
420 unmodified lines
421 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))422 self.assertEquals(rbody.get('data'), '')423424425 def test_GET_no_redirect(self):426427 for service in SERVICES:428429 r = requests.get(service('redirect', '3'), allow_redirects=False)430 self.assertEquals(r.status_code, 302)431 self.assertEquals(len(r.history), 0)432433434 def test_HEAD_no_redirect(self):435436 for service in SERVICES:437438 r = requests.head(service('redirect', '3'), allow_redirects=False)439 self.assertEquals(r.status_code, 302)440 self.assertEquals(len(r.history), 0)441442443 def test_redirect_history(self):444445 for service in SERVICES:446
47 unmodified lines