Rev 423: Address bugs #716201, and #716217. in http://bazaar.launchpad.net/~jameinel/loggerhead/no_template_for_head_716217
John Arbash Meinel
john at arbash-meinel.com
Thu Feb 10 05:49:26 UTC 2011
At http://bazaar.launchpad.net/~jameinel/loggerhead/no_template_for_head_716217
------------------------------------------------------------
revno: 423
revision-id: john at arbash-meinel.com-20110210054924-tdxcko62y6ouizq9
parent: mkanat at bugzilla.org-20101112000949-qhuz3vydzcvih8px
fixes bug(s): https://launchpad.net/bugs/716201 https://launchpad.net/bugs/716217
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: no_template_for_head_716217
timestamp: Wed 2011-02-09 23:49:24 -0600
message:
Address bugs #716201, and #716217.
Don't expand a template if we get a HEAD request.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2010-11-11 03:30:43 +0000
+++ b/NEWS 2011-02-10 05:49:24 +0000
@@ -1,6 +1,14 @@
What's changed in loggerhead?
=============================
+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)
+
+
1.18 [10Nov2010]
----------------
=== modified file 'info.py'
--- a/info.py 2010-11-11 03:30:43 +0000
+++ b/info.py 2011-02-10 05:49:24 +0000
@@ -6,7 +6,8 @@
bzr_plugin_version = (1, 18, 0)
bzr_compatible_versions = [
- (1, 17, 0), (1, 18, 0), (2, 0, 0), (2, 1, 0), (2, 2, 0), (2, 3, 0)]
+ (1, 17, 0), (1, 18, 0), (2, 0, 0), (2, 1, 0), (2, 2, 0), (2, 3, 0),
+ (2, 4, 0)]
bzr_minimum_version = bzr_compatible_versions[0]
=== modified file 'loggerhead/controllers/__init__.py'
--- a/loggerhead/controllers/__init__.py 2009-10-17 08:59:33 +0000
+++ b/loggerhead/controllers/__init__.py 2011-02-10 05:49:24 +0000
@@ -97,6 +97,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 2009-03-19 18:48:15 +0000
+++ b/loggerhead/tests/test_controllers.py 2011-02-10 05:49:24 +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