[Zope3-checkins] SVN: Zope3/trunk/ fix issue 586,
update the content-length header after a <base>
tag has been inserted.
Bjorn Tillenius
bjorn.tillenius at gmail.com
Tue Apr 18 12:15:56 EDT 2006
Log message for revision 67078:
fix issue 586, update the content-length header after a <base> tag has been inserted.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/publisher/browser.py
U Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2006-04-18 16:10:45 UTC (rev 67077)
+++ Zope3/trunk/doc/CHANGES.txt 2006-04-18 16:15:56 UTC (rev 67078)
@@ -131,6 +131,10 @@
- Fixed a bug in zope.publisher.http which raises a TypeError
when using zserver and xmlrpc.
+ - Fixed issue 586, BrowserResponse didn't update the
+ Content-Length header after inserting a <base> tag, causing
+ pages to be truncated in the browser.
+
Much thanks to everyone who contributed to this release:
Jim Fulton, Marius Gedminas, Brian Sutherland, Stephan Richter, Dmitry
Modified: Zope3/trunk/src/zope/publisher/browser.py
===================================================================
--- Zope3/trunk/src/zope/publisher/browser.py 2006-04-18 16:10:45 UTC (rev 67077)
+++ Zope3/trunk/src/zope/publisher/browser.py 2006-04-18 16:15:56 UTC (rev 67078)
@@ -679,6 +679,13 @@
body, headers = super(BrowserResponse, self)._implicitResult(body)
body = self.__insertBase(body)
+ # Update the Content-Length header to account for the inserted
+ # <base> tag.
+ headers = [
+ (name, value) for name, value in headers
+ if name != 'content-length'
+ ]
+ headers.append(('content-length', str(len(body))))
return body, headers
Modified: Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py
===================================================================
--- Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py 2006-04-18 16:10:45 UTC (rev 67077)
+++ Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py 2006-04-18 16:15:56 UTC (rev 67078)
@@ -107,7 +107,25 @@
self.assert_(isinstance(body, str))
self.assert_('<base href="http://localhost/folder" />' in result)
+ def testInsertBaseInSetResultUpdatesContentLength(self):
+ # Make sure that the Content-Length header is updated to account
+ # for an inserted <base> tag.
+ response = BrowserResponse()
+ response.setHeader('content-type', 'text/html')
+ base = 'http://localhost/folder/'
+ response.setBase(base)
+ inserted_text = '\n<base href="%s" />\n' % base
+ html_page = """<html>
+ <head></head>
+ <blah>
+ </html>
+ """
+ response.setResult(html_page)
+ self.assertEquals(
+ int(response.getHeader('content-length')),
+ len(html_page) + len(inserted_text))
+
def test_interface(self):
from zope.publisher.interfaces.http import IHTTPResponse
from zope.publisher.interfaces.http import IHTTPApplicationResponse
More information about the Zope3-Checkins
mailing list