Added Http.ignore_etag
diff --git a/httplib2/__init__.py b/httplib2/__init__.py
index 98bcfb0..31ba42d 100644
--- a/httplib2/__init__.py
+++ b/httplib2/__init__.py
@@ -549,6 +549,8 @@
self.follow_all_redirects = False
+ self.ignore_etag = False
+
def _auth_from_challenge(self, host, request_uri, headers, response, content):
"""A generator that creates Authorization objects
that can be applied to requests.
@@ -712,7 +714,7 @@
else:
cachekey = None
- if method in ["PUT"] and self.cache and info.has_key('etag'):
+ if method in ["PUT"] and self.cache and info.has_key('etag') and not self.ignore_etag:
# http://www.w3.org/1999/04/Editing/
headers['if-match'] = info['etag']
@@ -747,7 +749,7 @@
return (response, content)
if entry_disposition == "STALE":
- if info.has_key('etag'):
+ if info.has_key('etag') and not self.ignore_etag:
headers['if-none-match'] = info['etag']
if info.has_key('last-modified'):
headers['if-modified-since'] = info['last-modified']
diff --git a/httplib2test.py b/httplib2test.py
index fc969de..c07da86 100755
--- a/httplib2test.py
+++ b/httplib2test.py
@@ -252,6 +252,23 @@
self.assertEqual(response.status, 206)
self.assertEqual(response.fromcache, False)
+ def testGetIgnoreEtag(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.http.ignore_etag = True
+ (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'})
+ d = self.reflector(content)
+ self.assertEqual(response.fromcache, False)
+ self.assertFalse(d.has_key('HTTP_IF_NONE_MATCH'))
+
+
def testGet304EndToEnd(self):
# Test that end to end headers get overwritten in the cache
uri = urlparse.urljoin(base, "304/end2end.cgi")
@@ -555,7 +572,7 @@
self.assertEqual(response.status, 200)
def reflector(self, content):
- return dict( [tuple(x.split("=")) for x in content.strip().split("\n")] )
+ return dict( [tuple(x.split("=", 1)) for x in content.strip().split("\n")] )
def testReflector(self):
uri = urlparse.urljoin(base, "reflector/reflector.cgi")
diff --git a/libhttplib2.tex b/libhttplib2.tex
index a404c8b..f219fce 100644
--- a/libhttplib2.tex
+++ b/libhttplib2.tex
@@ -205,14 +205,17 @@
\end{methoddesc}
\begin{memberdesc}[Http]{follow_all_redirects}
-If \code{false}, which is the default, only safe redirects are followed, where
+If \code{False}, which is the default, only safe redirects are followed, where
safe means that the client is only doing a \code{GET} or \code{HEAD} on the
-URI to which it is being redirected. If \code{true} then all redirects are followed.
+URI to which it is being redirected. If \code{True} then all redirects are followed.
\end{memberdesc}
-
-
-
+\begin{memberdesc}[Http]{ignore_etag}
+Defaults to \code{False}. If True, then any etags present in the cached response
+are ignored when processing the current request, i.e. httplib2 does *not* use
+'if-match' for PUT or 'if-none-match' when GET or HEAD requests are made. This
+is mainly to deal with broken servers which supply an etag, but change it capriciously.
+\end{memberdesc}
\subsection{Cache Objects}
\label{cache-objects}