SVN: r25372 - trunk/quixote

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Fri, 15 Oct 2004 13:12:31 -0400
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-10-15 13:10:54 -0400 (Fri, 15 Oct 2004)
New Revision: 25372

Modified:
   trunk/quixote/http_response.py
   trunk/quixote/util.py
Log:
Add HTTPResponse.set_expires() method.  Perhaps 'cache' should be
renamed to 'expires'.


Modified: trunk/quixote/http_response.py
===================================================================
--- trunk/quixote/http_response.py	2004-10-15 16:57:22 UTC (rev 25371)
+++ trunk/quixote/http_response.py	2004-10-15 17:10:54 UTC (rev 25372)
@@ -174,6 +174,12 @@
         """
         return self.headers.get(name.lower(), default)
 
+    def set_expires(self, seconds=0, minutes=0, hours=0, days=0):
+        if seconds is None:
+            self.cache = None # don't generate 'Expires' header
+        else:
+            self.cache = seconds + 60*(minutes + 60*(hours + 24*days))
+
     def set_content_type(self, ctype):
         """set_content_type(ctype : string)
 

Modified: trunk/quixote/util.py
===================================================================
--- trunk/quixote/util.py	2004-10-15 16:57:22 UTC (rev 25371)
+++ trunk/quixote/util.py	2004-10-15 17:10:54 UTC (rev 25372)
@@ -177,13 +177,13 @@
         request.response.set_header('Last-Modified', last_modified)
 
         if self.cache_time is None:
-            request.response.cache = None # don't set the Expires header
+            request.response.set_expires(None) # don't set the Expires header
         else:
             # explicitly allow client to cache page by setting the Expires
             # header, this is even more efficient than the using
             # Last-Modified/If-Modified-Since since the browser does not need
             # to contact the server
-            request.response.cache = self.cache_time
+            request.response.set_expires(seconds=self.cache_time)
 
         return FileStream(open(self.path, 'rb'), stat.st_size)