summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2015-04-02 12:11:21 +0100
committerTimo Tijhof <krinklemail@gmail.com>2015-04-04 00:44:34 +0100
commit0ebd29371a9083a9ea050d6574a842a290992788 (patch)
tree84227cd967766cf4c521a5ac24244cf7e9f35672
parente1fe0ef1483d71536be2218006e138bb79e32796 (diff)
downloadzuul-0ebd29371a9083a9ea050d6574a842a290992788.tar.gz
web: Allow clients (browsers, proxies) to cache status.json
Follows-up aa4f2e7. While we're sending Last-Modified already, that's purely informational and doesn't do much. In theory proxies could figure it out by observing or polling the backend (with rate limiting) but afaik that isn't generally implemented. Web browsers typically send If-Modified-Since. So for requests coming from the users directly, Response.conditional_response_app handles the If-Modified-Since header and returns early with HTTPNotModified if needed (and no body content). In addition Cache-Control/Expires headers allow clients/proxies to handle it themselves (without even a 304 rountrip). This is preferred and informs the client of the actual expiry instead of having it ask us every time whether or not a timestamp is too old. Response: 200 OK Cache-Control: public, must-revalidate, max-age=(seconds) Expires: (RFC 2822 timestamp + seconds) Last-Modified: (RFC 2822 timestamp) Request: GET If-Modified-Since: (RFC 2822 timestamp) Response: 304 Not Modified Expires: (RFC 2822 timestamp + seconds) http://docs.webob.org/en/1.1/modules/webob.html Change-Id: I51f31f9d7965d805e147fda4070feead528601ac
-rwxr-xr-xtests/test_scheduler.py3
-rw-r--r--zuul/webapp.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index b44dba6c1..5712d7c6a 100755
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -2120,7 +2120,10 @@ class TestScheduler(ZuulTestCase):
self.assertIn('Content-Type', headers)
self.assertEqual(headers['Content-Type'],
'application/json; charset=UTF-8')
+ self.assertIn('Access-Control-Allow-Origin', headers)
+ self.assertIn('Cache-Control', headers)
self.assertIn('Last-Modified', headers)
+ self.assertIn('Expires', headers)
data = f.read()
self.worker.hold_jobs_in_build = False
diff --git a/zuul/webapp.py b/zuul/webapp.py
index e289398ac..44c333bf9 100644
--- a/zuul/webapp.py
+++ b/zuul/webapp.py
@@ -121,5 +121,10 @@ class WebApp(threading.Thread):
raise webob.exc.HTTPNotFound()
response.headers['Access-Control-Allow-Origin'] = '*'
+
+ response.cache_control.public = True
+ response.cache_control.max_age = self.cache_expiry
response.last_modified = self.cache_time
- return response
+ response.expires = self.cache_time + self.cache_expiry
+
+ return response.conditional_response_app