Fixed bug #1597318 User supplied if-* headers
diff --git a/httplib2/__init__.py b/httplib2/__init__.py
index e6805e6..fd4c768 100644
--- a/httplib2/__init__.py
+++ b/httplib2/__init__.py
@@ -795,7 +795,7 @@
else:
cachekey = None
- if method in ["PUT"] and self.cache and info.has_key('etag') and not self.ignore_etag:
+ if method in ["PUT"] and self.cache and info.has_key('etag') and not self.ignore_etag and 'if-match' not in headers:
# http://www.w3.org/1999/04/Editing/
headers['if-match'] = info['etag']
@@ -830,9 +830,9 @@
return (response, content)
if entry_disposition == "STALE":
- if info.has_key('etag') and not self.ignore_etag:
+ if info.has_key('etag') and not self.ignore_etag and not 'if-none-match' in headers:
headers['if-none-match'] = info['etag']
- if info.has_key('last-modified'):
+ if info.has_key('last-modified') and not 'last-modified' in headers:
headers['if-modified-since'] = info['last-modified']
elif entry_disposition == "TRANSPARENT":
pass
diff --git a/httplib2test.py b/httplib2test.py
index 5a7aeff..edda403 100755
--- a/httplib2test.py
+++ b/httplib2test.py
@@ -321,6 +321,21 @@
self.assertEqual(response.fromcache, False)
self.assertFalse(d.has_key('HTTP_IF_NONE_MATCH'))
+ def testOverrideEtag(self):
+ # Test that we can forcibly ignore ETags
+ uri = urlparse.urljoin(base, "reflector/reflector.cgi")
+ (response, content) = self.http.request(uri, "GET")
+ self.assertNotEqual(response['etag'], "")
+
+ (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'})
+ d = self.reflector(content)
+ self.assertTrue(d.has_key('HTTP_IF_NONE_MATCH'))
+ self.assertNotEqual(d['HTTP_IF_NONE_MATCH'], "fred")
+
+ (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0', 'if=none-match': 'fred'})
+ d = self.reflector(content)
+ self.assertTrue(d.has_key('HTTP_IF_NONE_MATCH'))
+ self.assertEqual(d['HTTP_IF_NONE_MATCH'], "fred")
def testGet304EndToEnd(self):
# Test that end to end headers get overwritten in the cache
@@ -513,6 +528,21 @@
(response, content) = self.http.request(uri, "PUT")
self.assertEqual(response.status, 412)
+ def testUpdateUsesCachedETagOverridden(self):
+ # Test that we natively support http://www.w3.org/1999/04/Editing/
+ uri = urlparse.urljoin(base, "conditional-updates/test.cgi")
+
+ (response, content) = self.http.request(uri, "GET")
+ self.assertEqual(response.status, 200)
+ self.assertEqual(response.fromcache, False)
+ (response, content) = self.http.request(uri, "GET")
+ self.assertEqual(response.status, 200)
+ self.assertEqual(response.fromcache, True)
+ (response, content) = self.http.request(uri, "PUT", headers={'if-match': 'fred'})
+ self.assertEqual(response.status, 412)
+
+
+
def testBasicAuth(self):
# Test Basic Authentication
uri = urlparse.urljoin(base, "basic/file.txt")