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

Changeset 1127

Show
Ignore:
Timestamp:
06/08/06 00:30:05
Author:
fumanchu
Message:

Fix for #509 (don't cache for POST, PUT, DELETE).

Files:

Legend:

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

    r1117 r1127  
    102102 
    103103def get(): 
    104     cacheData = cherrypy._cache.get() 
    105     cherrypy.request.cached = c = bool(cacheData) 
     104    # Ignore POST, PUT, DELETE. 
     105    # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10. 
     106    if cherrypy.request.method in cherrypy.config.get("tools.caching.invalid_methods", 
     107                                                      ("POST", "PUT", "DELETE")): 
     108        cherrypy.request.cached = c = False 
     109    else: 
     110        cacheData = cherrypy._cache.get() 
     111        cherrypy.request.cached = c = bool(cacheData) 
     112     
    106113    if c: 
    107114        expirationTime, lastModified, obj = cacheData 
  • trunk/cherrypy/test/test_caching.py

    r1114 r1127  
    3636            # The response should be the same every time! 
    3737            self.assertBody('visit #1') 
     38         
     39        # POST, PUT, DELETE should not be cached. 
     40        self.getPage("/", method="POST") 
     41        self.assertBody('visit #2') 
     42        self.getPage("/", method="GET") 
     43        self.assertBody('visit #2') 
     44        self.getPage("/", method="DELETE") 
     45        self.assertBody('visit #3') 
     46 
    3847 
    3948if __name__ == '__main__': 

Hosted by WebFaction

Log in as guest/cpguest to create tickets