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
Provenance
- Commit
aa04cc9- Tree
75d57b9- Author
Daniel Miller <danielm@vs-networks.com>- Committer
Daniel Miller <danielm@vs-networks.com>- Parent
8b64097
3 files changed+23 added−3 removed
modified:requests/api.py+4 added
88 unmodified lines89 :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 """96 97+ kwargs.setdefault('allow_redirects', True)98 return request('GET', url, **kwargs)99 100 101 def head(url, **kwargs):5 unmodified lines107 :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 """114 115+ kwargs.setdefault('allow_redirects', True)116 return request('HEAD', url, **kwargs)117 118 119 def post(url, data='', **kwargs):69 unmodified linesmodified:requests/models.py+1 added-3 removed
201 unmodified lines202 if r.status_code in REDIRECT_STATI and not self.redirect:203 204 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 ):208 209 r.close()210 411 unmodified linesmodified:test_requests.py+18 added
420 unmodified lines421 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))422 self.assertEquals(rbody.get('data'), '')423 424 425+ def test_GET_no_redirect(self):426+427+ for service in SERVICES:428+429+ r = requests.get(service('redirect', '3'), allow_redirects=False)430+ self.assertEquals(r.status_code, 302)431+ self.assertEquals(len(r.history), 0)432+433+434+ def test_HEAD_no_redirect(self):435+436+ for service in SERVICES:437+438+ r = requests.head(service('redirect', '3'), allow_redirects=False)439+ self.assertEquals(r.status_code, 302)440+ self.assertEquals(len(r.history), 0)441+442+443 def test_redirect_history(self):444 445 for service in SERVICES:446 47 unmodified lines