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
1=== modified file 'convoy/combo.py'
2--- convoy/combo.py 2013-08-20 14:48:24 +0000
3+++ convoy/combo.py 2014-12-12 08:05:15 +0000
4@@ -107,7 +107,7 @@
5 yield chunk
6
7
8-def combo_app(root, resource_prefix="", rewrite_urls=True):
9+def combo_app(root, resource_prefix="", rewrite_urls=True, max_age=None):
10 """A simple YUI Combo Service WSGI app.
11
12 Serves any files under C{root}, setting an appropriate
13@@ -139,8 +139,11 @@
14 start_response("400 Bad Request", [("Content-Type", content_type)])
15 return ("Bad Request",)
16 else:
17- start_response("200 OK", [("Content-Type", content_type),
18- ("X-Content-Type-Options", "nosniff")])
19+ headers = [("Content-Type", content_type),
20+ ("X-Content-Type-Options", "nosniff")]
21+ if max_age is not None:
22+ headers += [('Cache-Control', 'max-age=' + str(max_age))]
23+ start_response("200 OK", headers)
24
25 return combine_files(fnames, updated_root, resource_prefix,
26 rewrite_urls=rewrite_urls)
27
28=== modified file 'convoy/tests/test_combo.py'
29--- convoy/tests/test_combo.py 2013-08-20 14:48:24 +0000
30+++ convoy/tests/test_combo.py 2014-12-12 08:05:15 +0000
31@@ -492,6 +492,14 @@
32 # and ask for passwd, it's inside the new adjusted root
33 app.get("/../etc?yui-min&passwd", status=400)
34
35+ def test_cache_headers_set(self):
36+ app = TestApp(combo_app(self.root, max_age=3600))
37+ res = app.get("/?" + "&".join(
38+ ["widget/skin/sam/widget.css"]), status=200)
39+ self.assertEquals(res.headers, [("Content-Type", "text/css"),
40+ ("X-Content-Type-Options", "nosniff"),
41+ ('Cache-Control', 'max-age=3600')])
42+
43
44 def test_suite():
45 return defaultTestLoader.loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches

to all changes: