Changeset 1771
- Timestamp:
- 10/26/07 23:10:31
- Files:
-
- trunk/cherrypy/lib/caching.py (modified) (2 diffs)
- trunk/cherrypy/test/test_caching.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/caching.py
r1667 r1771 124 124 if c: 125 125 response = cherrypy.response 126 s, response.headers, b, create_time = cache_data 126 s, h, b, create_time = cache_data 127 128 # Make a copy. See http://www.cherrypy.org/ticket/721 129 response.headers = rh = http.HeaderMap() 130 for k in h: 131 dict.__setitem__(rh, k, dict.__getitem__(h, k)) 127 132 128 133 # Add the required Age header … … 134 139 # resurrected just above (response.headers = cache_data[1]). 135 140 cptools.validate_since() 136 except cherrypy.HTTP Error, x:141 except cherrypy.HTTPRedirect, x: 137 142 if x.status == 304: 138 143 cherrypy._cache.tot_non_modified += 1 trunk/cherrypy/test/test_caching.py
r1595 r1771 6 6 7 7 import cherrypy 8 from cherrypy.lib import http 9 10 gif_bytes = ('GIF89a\x01\x00\x01\x00\x82\x00\x01\x99"\x1e\x00\x00\x00\x00\x00' 11 '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 12 '\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x02\x03\x02\x08\t\x00;') 8 13 9 14 … … 22 27 return msg 23 28 index.exposed = True 24 29 30 def a_gif(self): 31 cherrypy.response.headers['Last-Modified'] = http.HTTPDate() 32 return gif_bytes 33 a_gif.exposed = True 34 25 35 class UnCached(object): 26 36 _cp_config = {'tools.expires.on': True, … … 162 172 d = self.assertHeader("Date") 163 173 self.assertHeader("Expires", d) 174 175 def testLastModified(self): 176 self.getPage("/a.gif") 177 self.assertStatus(200) 178 self.assertBody(gif_bytes) 179 lm1 = self.assertHeader("Last-Modified") 180 181 # this request should get the cached copy. 182 self.getPage("/a.gif") 183 self.assertStatus(200) 184 self.assertBody(gif_bytes) 185 self.assertHeader("Age") 186 lm2 = self.assertHeader("Last-Modified") 187 self.assertEqual(lm1, lm2) 188 189 # this request should match the cached copy, but raise 304. 190 self.getPage("/a.gif", [('If-Modified-Since', lm1)]) 191 self.assertStatus(304) 192 self.assertNoHeader("Last-Modified") 193 self.assertHeader("Age") 194 164 195 165 196 if __name__ == '__main__':

