Fixed https://sourceforge.net/tracker/?func=detail&atid=818434&aid=1459543&group_id=161082
diff --git a/httplib2/__init__.py b/httplib2/__init__.py
index 0c0c00b..f05f5c2 100644
--- a/httplib2/__init__.py
+++ b/httplib2/__init__.py
@@ -645,9 +645,15 @@
entry_disposition = _entry_disposition(info, headers)
if entry_disposition == "FRESH":
+ is_cached = os.path.exists(cacheFullPath)
+ if not is_cached:
+ info['status'] = '504'
+ content = ""
response = Response(info)
- response.fromcache = True
+ if is_cached:
+ response.fromcache = True
return (response, content)
+
elif entry_disposition == "STALE":
if info.has_key('etag'):
headers['if-none-match'] = info['etag']
diff --git a/httplib2test.py b/httplib2test.py
index edfd108..8b18e2a 100755
--- a/httplib2test.py
+++ b/httplib2test.py
@@ -66,6 +66,25 @@
self.assertEqual(response.status, 200)
self.assertEqual(response._previous, None)
+ def testGetOnlyIfCachedCacheMiss(self):
+ # Test that can do a GET with no cache with 'only-if-cached'
+ http = httplib2.Http(".cache")
+ uri = urlparse.urljoin(base, "304/test_etag.txt")
+ (response, content) = http.request(uri, "GET", headers={'cache-control': 'only-if-cached'})
+ self.assertEqual(response.fromcache, False)
+ self.assertEqual(response.status, 504)
+
+ def testGetOnlyIfCachedNoCacheAtAll(self):
+ # Test that can do a GET with no cache with 'only-if-cached'
+ # Of course, there might be an intermediary beyond us
+ # that responds to the 'only-if-cached', so this
+ # test can't really be guaranteed to pass.
+ http = httplib2.Http()
+ uri = urlparse.urljoin(base, "304/test_etag.txt")
+ (response, content) = http.request(uri, "GET", headers={'cache-control': 'only-if-cached'})
+ self.assertEqual(response.fromcache, False)
+ self.assertEqual(response.status, 200)
+
def testUserAgent(self):
# Test that we provide a default user-agent
uri = urlparse.urljoin(base, "user-agent/test.cgi")