POST redirect => GET
authorKenneth Reitz <me@kennethreitz.com>
Sat, 31 Mar 2012 03:28:07 +0000 (23:28 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 31 Mar 2012 03:28:07 +0000 (23:28 -0400)
#269

requests/models.py

index 881b7c1fc4e3dd243f7b283d1a6adbc7e8c988ff..b90f1a342e2efbf114353cad5b41f475fd0e2d74 100644 (file)
@@ -216,6 +216,7 @@ class Request(object):
         self.cookies.update(r.cookies)
 
         if r.status_code in REDIRECT_STATI and not self.redirect:
+
             while (('location' in r.headers) and
                    ((r.status_code is codes.see_other) or (self.allow_redirects))):
 
@@ -250,6 +251,15 @@ class Request(object):
                 else:
                     method = self.method
 
+                # Do what the browsers do if strict_mode is off...
+                if (not self.config.get('strict_mode')):
+
+                    if r.status_code in (codes.moved, codes.found) and self.method == 'POST':
+                        method = 'GET'
+
+                    if (r.status_code == 303) and self.method != 'HEAD':
+                        method = 'GET'
+
                 # Remove the cookie headers that were sent.
                 headers = self.headers
                 try: