Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1771

Show
Ignore:
Timestamp:
10/26/07 23:10:31
Author:
fumanchu
Message:

Fix for #721 (bugs in tools.caching).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/caching.py

    r1667 r1771  
    124124    if c: 
    125125        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)) 
    127132         
    128133        # Add the required Age header 
     
    134139            # resurrected just above (response.headers = cache_data[1]). 
    135140            cptools.validate_since() 
    136         except cherrypy.HTTPError, x: 
     141        except cherrypy.HTTPRedirect, x: 
    137142            if x.status == 304: 
    138143                cherrypy._cache.tot_non_modified += 1 
  • trunk/cherrypy/test/test_caching.py

    r1595 r1771  
    66 
    77import cherrypy 
     8from cherrypy.lib import http 
     9 
     10gif_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;') 
    813 
    914 
     
    2227            return msg 
    2328        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     
    2535    class UnCached(object): 
    2636        _cp_config = {'tools.expires.on': True, 
     
    162172        d = self.assertHeader("Date") 
    163173        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 
    164195 
    165196if __name__ == '__main__': 

Hosted by WebFaction

Log in as guest/cpguest to create tickets