diff roundup/cgi/client.py @ 5980:54d0080769f9

Support setting cache-control headers for static files Control how to cache static files. Can control by mime type or filename. Needs to use interfaces.py mechanism to configure. See customization.txt file in the interfaces.py section. Also added docs for using interfacs.py and a few examples.
author John Rouillard <rouilj@ieee.org>
date Thu, 21 Nov 2019 20:50:56 -0500
parents 1b50c2c5619a
children 6ed03d01491d
line wrap: on
line diff
--- a/roundup/cgi/client.py	Thu Nov 14 21:37:13 2019 -0500
+++ b/roundup/cgi/client.py	Thu Nov 21 20:50:56 2019 -0500
@@ -341,6 +341,8 @@
         errno.ETIMEDOUT,
     )
 
+    Cache_Control = {}
+    
     def __init__(self, instance, request, env, form=None, translator=None):
         # re-seed the random number generator. Is this is an instance of
         # random.SystemRandom it has no effect.
@@ -1711,6 +1713,17 @@
             else:
                 mime_type = 'text/plain'
 
+        # get filename: given a/b/c.js extract c.js
+        fn=file.rpartition("/")[2]
+        if fn in self.Cache_Control:
+            # if filename matches, don't use cache control
+            # for mime type.
+            self.additional_headers['Cache-Control'] = \
+                            self.Cache_Control[fn]
+        elif mime_type in self.Cache_Control:
+            self.additional_headers['Cache-Control'] = \
+                            self.Cache_Control[mime_type]
+            
         self._serve_file(lmt, mime_type, '', filename)
 
     def _serve_file(self, lmt, mime_type, content=None, filename=None):

Roundup Issue Tracker: http://roundup-tracker.org/