Skip to content

Commit 7f752bb

Browse files
committed
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.
1 parent 5d59ad3 commit 7f752bb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

roundup/cgi/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ class Client:
340340
# Key can be explicitly file basename - value applied to just that file
341341
# takes precedence over mime type.
342342
# Key can be mime type - all files of that mimetype will get the value
343-
Cache_Control = {}
343+
Cache_Control = {
344+
'application/javascript': "public, max-age=1209600", # 2 weeks
345+
'text/css': "public, max-age=4838400", # 8 weeks/2 months
346+
}
344347

345348
# list of valid http compression (Content-Encoding) algorithms
346349
# we have available

test/test_liveserver.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,33 @@ def test_compression_zstd(self):
868868
self.assertDictEqual({ key: value for (key, value) in
869869
f.headers.items() if key in expected },
870870
expected)
871+
872+
def test_cache_control_css(self):
873+
f = requests.get(self.url_base() + '/@@file/style.css',
874+
headers = {'content-type': "",
875+
'Accept': '*/*'})
876+
print(f.status_code)
877+
print(f.headers)
878+
879+
self.assertEqual(f.status_code, 200)
880+
self.assertEqual(f.headers['Cache-Control'], 'public, max-age=4838400')
881+
882+
f = requests.get(self.url_base() + '/@@file/style.css',
883+
headers = {'content-type': "",
884+
'Accept': '*/*'})
885+
print(f.status_code)
886+
print(f.headers)
887+
888+
self.assertEqual(f.status_code, 200)
889+
self.assertEqual(f.headers['Cache-Control'], 'public, max-age=4838400')
890+
891+
def test_cache_control_js(self):
892+
f = requests.get(self.url_base() + '/@@file/help_controls.js',
893+
headers = {'content-type': "",
894+
'Accept': '*/*'})
895+
print(f.status_code)
896+
print(f.headers)
897+
898+
self.assertEqual(f.status_code, 200)
899+
self.assertEqual(f.headers['Cache-Control'], 'public, max-age=1209600')
900+

0 commit comments

Comments
 (0)