Rev 424: Merge the "don't run template on HEAD requests" branch. in http://bazaar.launchpad.net/~loggerhead-team/loggerhead/trunk-rich
John Arbash Meinel
john at arbash-meinel.com
Thu Feb 10 17:01:32 UTC 2011
At http://bazaar.launchpad.net/~loggerhead-team/loggerhead/trunk-rich
------------------------------------------------------------
revno: 424 [merge]
revision-id: john at arbash-meinel.com-20110210170110-3dqpwtafdru826kr
parent: john at arbash-meinel.com-20110210131153-wxbw9wddbr0rpvql
parent: john at arbash-meinel.com-20110210054924-tdxcko62y6ouizq9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk-rich
timestamp: Thu 2011-02-10 11:01:10 -0600
message:
Merge the "don't run template on HEAD requests" branch.
This should stop us from getting OOPS during HEAD requests from haproxy
(bug #701329). It also should mean that at least most HEAD requests stop
returning body content (bug #716201), and that we perform less total work
to return HEAD info (bug #716217).
modified:
NEWS news-20070121024650-6cwmhprgtcegpxvm-1
loggerhead/controllers/__init__.py __init__.py-20061211064342-102iqirsciyvgtcf-17
loggerhead/tests/test_controllers.py test_controllers.py-20090210051739-5d14nlvjvn2ep4x5-1
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2011-02-09 22:54:31 +0000
+++ b/NEWS 2011-02-10 17:01:10 +0000
@@ -2,11 +2,16 @@
=============================
1.19 [???]
-----------
+----------------
+
+ - If we get a HEAD request, there is no reason to expand the template, we
+ shouldn't be returning body content anyway.
+ (John Arbash Meinel, #716201, #716217)
- Merge the pqm changes back into trunk, after trunk was reverted to an old
revision. (John Arbash Meinel, #716152)
+
1.18 [10Nov2010]
----------------
=== modified file 'loggerhead/controllers/__init__.py'
--- a/loggerhead/controllers/__init__.py 2011-01-20 07:28:21 +0000
+++ b/loggerhead/controllers/__init__.py 2011-02-10 17:01:10 +0000
@@ -99,6 +99,9 @@
if 'Content-Type' not in headers:
headers['Content-Type'] = 'text/html'
writer = start_response("200 OK", headers.items())
+ if environ.get('REQUEST_METHOD') == 'HEAD':
+ # No content for a HEAD request
+ return []
template = load_template(self.template_path)
z = time.time()
w = BufferingWriter(writer, 8192)
=== modified file 'loggerhead/tests/test_controllers.py'
--- a/loggerhead/tests/test_controllers.py 2011-02-09 22:35:16 +0000
+++ b/loggerhead/tests/test_controllers.py 2011-02-10 17:01:10 +0000
@@ -1,3 +1,10 @@
+from cStringIO import StringIO
+import logging
+
+from paste.httpexceptions import HTTPServerError
+
+from bzrlib import errors
+
from loggerhead.apps.branch import BranchWSGIApp
from loggerhead.controllers.annotate_ui import AnnotateUI
from loggerhead.controllers.inventory_ui import InventoryUI
@@ -15,15 +22,50 @@
tree.commit('')
tree.branch.lock_read()
self.addCleanup(tree.branch.unlock)
- branch_app = BranchWSGIApp(tree.branch)
+ branch_app = BranchWSGIApp(tree.branch, '')
+ branch_app.log.setLevel(logging.CRITICAL)
+ # These are usually set in BranchWSGIApp.app(), which is set from env
+ # settings set by BranchesFromTransportRoot, so we fake it.
+ branch_app._static_url_base = '/'
+ branch_app._url_base = '/'
return tree.branch, InventoryUI(branch_app, branch_app.get_history)
+ def consume_app(self, app, extra_environ=None):
+ env = {'SCRIPT_NAME': '/files', 'PATH_INFO': ''}
+ if extra_environ is not None:
+ env.update(extra_environ)
+ body = StringIO()
+ start = []
+ def start_response(status, headers, exc_info=None):
+ start.append((status, headers, exc_info))
+ return body.write
+ extra_content = list(app(env, start_response))
+ body.writelines(extra_content)
+ return start[0], body.getvalue()
+
def test_get_filelist(self):
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
['filename'])
inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
+ def test_smoke(self):
+ bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
+ ['filename'])
+ start, content = self.consume_app(inv_ui)
+ self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
+ start)
+ self.assertContainsRe(content, 'filename')
+
+ def test_no_content_for_HEAD(self):
+ bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
+ ['filename'])
+ start, content = self.consume_app(inv_ui,
+ extra_environ={'REQUEST_METHOD': 'HEAD'})
+ self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
+ start)
+ self.assertEqual('', content)
+
class TestRevisionUI(BasicTests):
More information about the bazaar-commits
mailing list