Merge lp:~fabricematrat/convoy/trunk into lp:convoy

Proposed by Fabrice Matrat
Status: Merged
Merged at revision: 26
Proposed branch: lp:~fabricematrat/convoy/trunk
Merge into: lp:convoy
Diff against target: 45 lines (+14/-3)
2 files modified
convoy/combo.py (+6/-3)
convoy/tests/test_combo.py (+8/-0)
To merge this branch: bzr merge lp:~fabricematrat/convoy/trunk
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+244440@code.launchpad.net

Description of the change

Add the capability to specify a max age for the response.
This will add a cache header on ther esponse

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

I think it would be nicer to set a variable to be the common list of items for both situations that is used as the second parameter to start_response. Then if max_age is not None you could append to the list followed by a single call to start_response.

Otherwise LGTM

review: Approve (code)
Revision history for this message
Kyle Adams (kadams54) wrote :

LGTM aside from Brad's comments.

lp:~fabricematrat/convoy/trunk updated
27. By Fabrice Matrat

Extract headers to variable

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'convoy/combo.py'
--- convoy/combo.py 2013-08-20 14:48:24 +0000
+++ convoy/combo.py 2014-12-12 08:05:15 +0000
@@ -107,7 +107,7 @@
107 yield chunk107 yield chunk
108108
109109
110def combo_app(root, resource_prefix="", rewrite_urls=True):110def combo_app(root, resource_prefix="", rewrite_urls=True, max_age=None):
111 """A simple YUI Combo Service WSGI app.111 """A simple YUI Combo Service WSGI app.
112112
113 Serves any files under C{root}, setting an appropriate113 Serves any files under C{root}, setting an appropriate
@@ -139,8 +139,11 @@
139 start_response("400 Bad Request", [("Content-Type", content_type)])139 start_response("400 Bad Request", [("Content-Type", content_type)])
140 return ("Bad Request",)140 return ("Bad Request",)
141 else:141 else:
142 start_response("200 OK", [("Content-Type", content_type),142 headers = [("Content-Type", content_type),
143 ("X-Content-Type-Options", "nosniff")])143 ("X-Content-Type-Options", "nosniff")]
144 if max_age is not None:
145 headers += [('Cache-Control', 'max-age=' + str(max_age))]
146 start_response("200 OK", headers)
144147
145 return combine_files(fnames, updated_root, resource_prefix,148 return combine_files(fnames, updated_root, resource_prefix,
146 rewrite_urls=rewrite_urls)149 rewrite_urls=rewrite_urls)
147150
=== modified file 'convoy/tests/test_combo.py'
--- convoy/tests/test_combo.py 2013-08-20 14:48:24 +0000
+++ convoy/tests/test_combo.py 2014-12-12 08:05:15 +0000
@@ -492,6 +492,14 @@
492 # and ask for passwd, it's inside the new adjusted root492 # and ask for passwd, it's inside the new adjusted root
493 app.get("/../etc?yui-min&passwd", status=400)493 app.get("/../etc?yui-min&passwd", status=400)
494494
495 def test_cache_headers_set(self):
496 app = TestApp(combo_app(self.root, max_age=3600))
497 res = app.get("/?" + "&".join(
498 ["widget/skin/sam/widget.css"]), status=200)
499 self.assertEquals(res.headers, [("Content-Type", "text/css"),
500 ("X-Content-Type-Options", "nosniff"),
501 ('Cache-Control', 'max-age=3600')])
502
495503
496def test_suite():504def test_suite():
497 return defaultTestLoader.loadTestsFromName(__name__)505 return defaultTestLoader.loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches

to all changes: