summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjcgregorio@localhost <jcgregorio@localhost>2010-05-13 23:42:11 -0400
committerjcgregorio@localhost <jcgregorio@localhost>2010-05-13 23:42:11 -0400
commit9e603dad1614ec73e02bd0dc9b59d98ec34903b0 (patch)
tree9f8778f36094e8b555b1e508920fd5214921ada4
parent4e8a2bc3c39cc3a8b3a0919d640ea06b68e51bd1 (diff)
downloadhttplib2-9e603dad1614ec73e02bd0dc9b59d98ec34903b0.tar.gz
Fix for issue #94 by Leonard Richardson
-rw-r--r--python2/httplib2/__init__.py2
-rwxr-xr-xpython2/httplib2test.py13
-rw-r--r--python3/httplib2/__init__.py2
-rwxr-xr-xpython3/httplib2test.py13
-rw-r--r--test/vary/unused-header.asis6
5 files changed, 34 insertions, 2 deletions
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py
index 3054051..21dc86a 100644
--- a/python2/httplib2/__init__.py
+++ b/python2/httplib2/__init__.py
@@ -1064,7 +1064,7 @@ a string that contains the response entity body.
for header in vary_headers:
key = '-varied-%s' % header
value = info[key]
- if headers.get(header, '') != value:
+ if headers.get(header, None) != value:
cached_value = None
break
diff --git a/python2/httplib2test.py b/python2/httplib2test.py
index 2c132af..5a81a70 100755
--- a/python2/httplib2test.py
+++ b/python2/httplib2test.py
@@ -636,6 +636,19 @@ class HttpTest(unittest.TestCase):
self.assertEqual(response.status, 200)
self.assertEqual(response.fromcache, False, msg="Should not be from cache")
+ def testVaryUnusedHeader(self):
+ # A header's value is not considered to vary if it's not used at all.
+ uri = urlparse.urljoin(base, "vary/unused-header.asis")
+ (response, content) = self.http.request(uri, "GET", headers={
+ 'Accept': 'text/plain'})
+ self.assertEqual(response.status, 200)
+ self.assertTrue(response.has_key('vary'))
+
+ # we are from cache
+ (response, content) = self.http.request(uri, "GET", headers={
+ 'Accept': 'text/plain',})
+ self.assertEqual(response.fromcache, True, msg="Should be from cache")
+
def testHeadGZip(self):
# Test that we don't try to decompress a HEAD response
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py
index ccd4d46..5ca8c3a 100644
--- a/python3/httplib2/__init__.py
+++ b/python3/httplib2/__init__.py
@@ -1052,7 +1052,7 @@ a string that contains the response entity body.
for header in vary_headers:
key = '-varied-%s' % header
value = info[key]
- if headers.get(header, '') != value:
+ if headers.get(header, None) != value:
cached_value = None
break
diff --git a/python3/httplib2test.py b/python3/httplib2test.py
index 46a850d..264677c 100755
--- a/python3/httplib2test.py
+++ b/python3/httplib2test.py
@@ -634,6 +634,19 @@ class HttpTest(unittest.TestCase):
self.assertEqual(response.status, 200)
self.assertEqual(response.fromcache, False, msg="Should not be from cache")
+ def testVaryUnusedHeader(self):
+ # A header's value is not considered to vary if it's not used at all.
+ uri = urllib.parse.urljoin(base, "vary/unused-header.asis")
+ (response, content) = self.http.request(uri, "GET", headers={
+ 'Accept': 'text/plain'})
+ self.assertEqual(response.status, 200)
+ self.assertTrue('vary' in response)
+
+ # we are from cache
+ (response, content) = self.http.request(uri, "GET", headers={
+ 'Accept': 'text/plain',})
+ self.assertEqual(response.fromcache, True, msg="Should be from cache")
+
def testHeadGZip(self):
# Test that we don't try to decompress a HEAD response
uri = urllib.parse.urljoin(base, "gzip/final-destination.txt")
diff --git a/test/vary/unused-header.asis b/test/vary/unused-header.asis
new file mode 100644
index 0000000..2002f48
--- /dev/null
+++ b/test/vary/unused-header.asis
@@ -0,0 +1,6 @@
+#!/usr/bin/tail --lines=+2
+Content-Type: text/plain
+Vary: X-No-Such-Header
+Status: 200 OK
+
+I've never heard of a header called X-No-Such-Header.