diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py index 9fe28b9..9f15524 100644 --- a/python2/httplib2/__init__.py +++ b/python2/httplib2/__init__.py @@ -1204,6 +1204,9 @@ def __init__(self, cache=None, timeout=None, # If set to False then no redirects are followed, even safe ones. self.follow_redirects = True + self.save_redirect_histories = False + + self.redirect_histories = [] # Which HTTP methods do we apply optimistic concurrency to, i.e. # which methods get an "if-match:" etag header added to them. @@ -1256,6 +1259,9 @@ def add_certificate(self, key, cert, domain): any time a request requires authentication.""" self.certificates.add(key, cert, domain) + def clear_redirects_list(self): + self.redirect_histories = [] + def clear_credentials(self): """Remove all the names and passwords that are used for authentication""" @@ -1394,6 +1400,7 @@ def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, if not old_response.has_key('content-location'): old_response['content-location'] = absolute_uri redirect_method = method + if response.status in [302, 303]: redirect_method = "GET" body = None @@ -1402,6 +1409,9 @@ def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, body=body, headers=headers, redirections=redirections - 1) response.previous = old_response + + if self.save_redirect_histories: + self.redirect_histories.insert(0, location) else: raise RedirectLimit("Redirected more times than rediection_limit allows.", response, content) elif response.status in [200, 203] and method in ["GET", "HEAD"]: diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py index 43f7419..514fbbd 100644 --- a/python3/httplib2/__init__.py +++ b/python3/httplib2/__init__.py @@ -914,6 +914,9 @@ def __init__(self, cache=None, timeout=None, # If set to False then no redirects are followed, even safe ones. self.follow_redirects = True + self.save_redirect_histories = True + + self.redirect_histories = [] # Which HTTP methods do we apply optimistic concurrency to, i.e. # which methods get an "if-match:" etag header added to them. @@ -966,6 +969,9 @@ def add_certificate(self, key, cert, domain): any time a request requires authentication.""" self.certificates.add(key, cert, domain) + def clear_redirects_list(self): + self.redirect_histories = [] + def clear_credentials(self): """Remove all the names and passwords that are used for authentication""" @@ -1109,6 +1115,9 @@ def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, location, method=redirect_method, body=body, headers=headers, redirections=redirections - 1) response.previous = old_response + + if self.save_redirect_histories: + self.redirect_histories.insert(0, location) else: raise RedirectLimit("Redirected more times than redirection_limit allows.", response, content) elif response.status in [200, 203] and method in ["GET", "HEAD"]: