[Zope3-checkins] SVN: Zope3/branches/3.2/ Backport from trunk:

Bjorn Tillenius bjorn.tillenius at gmail.com
Tue Apr 18 12:22:46 EDT 2006


Log message for revision 67079:
  Backport from trunk:
  
  ------------------------------------------------------------------------
  r67078 | BjornT | 2006-04-18 19:15:56 +0300 (Tue, 18 Apr 2006) | 1 line
  
  fix issue 586, update the content-length header after a <base> tag has been
  inserted.
  ------------------------------------------------------------------------
  
  

Changed:
  U   Zope3/branches/3.2/doc/CHANGES.txt
  U   Zope3/branches/3.2/src/zope/publisher/browser.py
  U   Zope3/branches/3.2/src/zope/publisher/tests/test_browserresponse.py

-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt	2006-04-18 16:15:56 UTC (rev 67078)
+++ Zope3/branches/3.2/doc/CHANGES.txt	2006-04-18 16:22:46 UTC (rev 67079)
@@ -26,6 +26,11 @@
         instances or as root. the default was zdsock in the directory
         where zopectl is started from.
 
+      - Fixed issue 586, BrowserResponse didn't update the
+        Content-Length header after inserting a <base> tag, causing
+        pages to be truncated in the browser.
+
+
   Zope 3.2.1 (2006/03/26)
 
     Bug fixes

Modified: Zope3/branches/3.2/src/zope/publisher/browser.py
===================================================================
--- Zope3/branches/3.2/src/zope/publisher/browser.py	2006-04-18 16:15:56 UTC (rev 67078)
+++ Zope3/branches/3.2/src/zope/publisher/browser.py	2006-04-18 16:22:46 UTC (rev 67079)
@@ -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/branches/3.2/src/zope/publisher/tests/test_browserresponse.py
===================================================================
--- Zope3/branches/3.2/src/zope/publisher/tests/test_browserresponse.py	2006-04-18 16:15:56 UTC (rev 67078)
+++ Zope3/branches/3.2/src/zope/publisher/tests/test_browserresponse.py	2006-04-18 16:22:46 UTC (rev 67079)
@@ -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