From efc2ab972e1fca89577a7308cae7ba4eb8ea3b99 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Wed, 12 Sep 2018 16:48:19 -0600 Subject: [PATCH] Correct Last-Modified header for status API Currently, the Last-Modified header is returned as a UNIX timestamp, whereas according to RFC 7232, it should be in a human-readable date format. Comply with the RFC. Change-Id: Id12482750e556809e731db6b3bb09d89234bac63 --- tests/unit/test_web.py | 1 + zuul/web/__init__.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_web.py b/tests/unit/test_web.py index 64aa2a1466..cabc505bfa 100755 --- a/tests/unit/test_web.py +++ b/tests/unit/test_web.py @@ -109,6 +109,7 @@ class TestWeb(BaseTestWeb): self.assertIn('Access-Control-Allow-Origin', resp.headers) self.assertIn('Cache-Control', resp.headers) self.assertIn('Last-Modified', resp.headers) + self.assertTrue(resp.headers['Last-Modified'].endswith(' GMT')) self.executor_server.hold_jobs_in_build = False self.executor_server.release() diff --git a/zuul/web/__init__.py b/zuul/web/__init__.py index 8b0efbe0a4..1f402f371e 100755 --- a/zuul/web/__init__.py +++ b/zuul/web/__init__.py @@ -21,6 +21,7 @@ from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool from ws4py.websocket import WebSocket import codecs import copy +from datetime import datetime import json import logging import os @@ -245,7 +246,9 @@ class ZuulWebAPI(object): resp = cherrypy.response resp.headers["Cache-Control"] = "public, max-age=%d" % \ self.cache_expiry - resp.headers["Last-modified"] = self.cache_time[tenant] + last_modified = datetime.utcfromtimestamp(self.cache_time[tenant]) + last_modified_header = last_modified.strftime('%a, %d %b %Y %X GMT') + resp.headers["Last-modified"] = last_modified_header resp.headers['Access-Control-Allow-Origin'] = '*' return payload