Fixes issue 123.
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py
index 1f7096d..3907013 100644
--- a/python3/httplib2/__init__.py
+++ b/python3/httplib2/__init__.py
@@ -967,7 +967,9 @@
old_response = copy.deepcopy(response)
if 'content-location' not in old_response:
old_response['content-location'] = absolute_uri
- redirect_method = ((response.status == 303) and (method not in ["GET", "HEAD"])) and "GET" or method
+ redirect_method = method
+ if response.status == 303:
+ redirect_method = "GET"
(response, content) = self.request(location, redirect_method, body=body, headers = headers, redirections = redirections - 1)
response.previous = old_response
else:
diff --git a/python3/httplib2test.py b/python3/httplib2test.py
index ebaf416..5e7e930 100755
--- a/python3/httplib2test.py
+++ b/python3/httplib2test.py
@@ -330,6 +330,13 @@
self.assertEqual(response.previous.status, 301)
self.assertEqual(response.previous.fromcache, True)
+ def testHead301(self):
+ # Test that we automatically follow 301 redirects
+ uri = urllib.parse.urljoin(base, "301/onestep.asis")
+ (response, content) = self.http.request(uri, "HEAD")
+ self.assertEqual(response.status, 200)
+ self.assertEqual(response.previous.status, 301)
+ self.assertEqual(response.previous.fromcache, False)
def testGet301NoRedirect(self):
# Test that we automatically follow 301 redirects