@@ -79,6 +79,31 @@ def test_etags_get_example(self, sess, server):
79
79
# Make sure we updated our cache with the new etag'd response.
80
80
assert self .cache .get (self .etag_url ) == resp .raw
81
81
82
+ def test_etags_get_no_cache (self , sess , server ):
83
+ """A 'Cache-Control: no-cache' header stops us from using the cache directly,
84
+ but not from using the 'If-None-Match' header on the request."""
85
+ # get our response
86
+ r = sess .get (self .etag_url )
87
+ assert "if-none-match" not in r .request .headers
88
+
89
+ r = sess .get (self .etag_url , headers = {"Cache-Control" : "no-cache" })
90
+ assert "if-none-match" in r .request .headers
91
+ assert r .status_code == 200
92
+
93
+ # This response does come from the cache, but only after the 304 response from
94
+ # the server told us that was fine.
95
+ assert r .from_cache
96
+
97
+ def test_etags_get_with_range (self , sess , server ):
98
+ """A 'Range' header stops us from using the cache altogether."""
99
+ # get our response
100
+ r = sess .get (self .etag_url )
101
+
102
+ r = sess .get (self .etag_url , headers = {"Range" : "0-10" })
103
+ assert "if-none-match" not in r .request .headers
104
+ assert r .status_code == 200
105
+ assert not r .from_cache
106
+
82
107
83
108
class TestDisabledETags :
84
109
"""Test our use of ETags when the response is stale and the
0 commit comments