Fixed logic for auto redirect in GET and HEAD methods.
authorverm666 <verm666@gmail.com>
Mon, 29 Aug 2011 16:01:27 +0000 (20:01 +0400)
committerKenneth Reitz <me@kennethreitz.com>
Fri, 2 Sep 2011 19:44:18 +0000 (15:44 -0400)
requests/api.py
requests/models.py
test_requests.py

index cd522c2..102bc75 100644 (file)
@@ -95,6 +95,9 @@ def get(url, **kwargs):
     :param **kwargs: Optional arguments that ``request`` takes.
     """
 
+    if "allow_redirects" not in kwargs:
+        kwargs["allow_redirects"] = True
+
     return request('get', url, **kwargs)
 
 
@@ -105,6 +108,9 @@ def head(url, **kwargs):
     :param **kwargs: Optional arguments that ``request`` takes.
     """
 
+    if "allow_redirects" not in kwargs:
+        kwargs["allow_redirects"] = True
+
     return request('head', url, **kwargs)
 
 
index 5ff9eb4..a951ab9 100644 (file)
@@ -212,8 +212,7 @@ class Request(object):
 
             while (
                 ('location' in r.headers) and
-                ((self.method in ('GET', 'HEAD')) or
-                (r.status_code is codes.see_other) or
+                ((r.status_code is codes.see_other) or
                 (self.allow_redirects))
             ):
 
index dd92347..e3db01d 100755 (executable)
@@ -60,6 +60,13 @@ class RequestsTestSuite(unittest.TestCase):
         r = requests.get(httpbin('/'))
         self.assertEqual(r.status_code, 200)
 
+    def test_HTTP_302_ALLOW_REDIRECT_GET(self):
+       r = requests.get(httpbin('redirect', '1'))
+       self.assertEqual(r.status_code, 200)
+
+    def test_HTTP_302_GET(self):
+       r = requests.get(httpbin('redirect', '1'), allow_redirects=False)
+       self.assertEqual(r.status_code, 302)
 
     def test_HTTPS_200_OK_GET(self):
         r = requests.get(httpsbin('/'))