changeset 6546:c58c7cd31243

issue2550991 - Some mechanism to set expiration header or max age for static resources Work was done in 2.0.0 to add support for cache control headers. This checkin sets default values for javascript (2 weeks) and css (2 month) files.
author John Rouillard <rouilj@ieee.org>
date Thu, 09 Dec 2021 17:36:08 -0500
parents 5a3a386aa8e7
children 3cae70995eff
files roundup/cgi/client.py test/test_liveserver.py
diffstat 2 files changed, 34 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/cgi/client.py	Thu Dec 09 15:26:39 2021 -0500
+++ b/roundup/cgi/client.py	Thu Dec 09 17:36:08 2021 -0500
@@ -340,7 +340,10 @@
     # Key can be explicitly file basename - value applied to just that file
     #     takes precedence over mime type.
     # Key can be mime type - all files of that mimetype will get the value
-    Cache_Control = {}
+    Cache_Control = {
+        'application/javascript': "public, max-age=1209600", # 2 weeks
+        'text/css':               "public, max-age=4838400", # 8 weeks/2 months
+    }
 
     # list of valid http compression (Content-Encoding) algorithms
     # we have available
--- a/test/test_liveserver.py	Thu Dec 09 15:26:39 2021 -0500
+++ b/test/test_liveserver.py	Thu Dec 09 17:36:08 2021 -0500
@@ -868,3 +868,33 @@
         self.assertDictEqual({ key: value for (key, value) in
                                f.headers.items() if key in expected },
                              expected)
+
+    def test_cache_control_css(self):
+        f = requests.get(self.url_base() + '/@@file/style.css',
+                             headers = {'content-type': "",
+                                        'Accept': '*/*'})
+        print(f.status_code)
+        print(f.headers)
+
+        self.assertEqual(f.status_code, 200)
+        self.assertEqual(f.headers['Cache-Control'], 'public, max-age=4838400')
+
+        f = requests.get(self.url_base() + '/@@file/style.css',
+                             headers = {'content-type': "",
+                                        'Accept': '*/*'})
+        print(f.status_code)
+        print(f.headers)
+
+        self.assertEqual(f.status_code, 200)
+        self.assertEqual(f.headers['Cache-Control'], 'public, max-age=4838400')
+
+    def test_cache_control_js(self):
+        f = requests.get(self.url_base() + '/@@file/help_controls.js',
+                             headers = {'content-type': "",
+                                        'Accept': '*/*'})
+        print(f.status_code)
+        print(f.headers)
+
+        self.assertEqual(f.status_code, 200)
+        self.assertEqual(f.headers['Cache-Control'], 'public, max-age=1209600')
+

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