[http] closes #1816411, restore expires_header on static files in non-debug mode
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 11 Jul 2011 15:05:19 +0200
changeset 7647 af352bf06ae4
parent 7646 91a984ba420f
child 7648 5d5d98930247
[http] closes #1816411, restore expires_header on static files in non-debug mode
etwist/server.py
--- a/etwist/server.py	Mon Jul 11 13:45:04 2011 +0200
+++ b/etwist/server.py	Mon Jul 11 15:05:19 2011 +0200
@@ -78,6 +78,15 @@
 
 
 class NoListingFile(static.File):
+
+    def set_expires(self, request):
+        if not self.config.debugmode:
+            # XXX: Don't provide additional resource information to error responses
+            #
+            # the HTTP RFC recommands not going further than 1 year ahead
+            expires = date.today() + timedelta(days=6*30)
+            request.setHeader('Expires', generateDateTime(mktime(expires.timetuple())))
+
     def directoryListing(self):
         return ForbiddenDirectoryLister()
 
@@ -107,6 +116,7 @@
                 if resource_relpath:
                     paths = resource_relpath.split(',')
                     try:
+                        self.set_expires(request)
                         return ConcatFiles(self.config, paths)
                     except ConcatFileNotFoundError:
                         return self.childNotFound
@@ -124,6 +134,7 @@
             self.putChild(path, resource)
             return resource
         else:
+            self.set_expires(request)
             return NoListingFile(filepath)
 
 
@@ -157,14 +168,6 @@
     def _defineChildResources(self):
         pass
 
-    def render(self, request):
-        # XXX: Don't provide additional resource information to error responses
-        #
-        # the HTTP RFC recommands not going further than 1 year ahead
-        expires = date.today() + timedelta(days=6*30)
-        request.setHeader('Expires', generateDateTime(mktime(expires.timetuple())))
-        return DataLookupDirectory.render(self, request)
-
 
 class ConcatFileNotFoundError(CubicWebException):
     pass