[Zope3-checkins] SVN: Zope3/trunk/src/zope/publisher/ Forward-port from 3.0-branch:

Bjorn Tillenius bjoti777 at student.liu.se
Sun Dec 19 06:38:03 EST 2004


Log message for revision 28650:
  Forward-port from 3.0-branch:
  
  ------------------------------------------------------------------------
  r28649 | BjornT | 2004-12-19 13:08:32 +0200 (Sun, 19 Dec 2004) | 3 lines
  
  If the content-type was text/*, HTTPRespnse.write re-set the content-length
  header to the first chunk of data.
  
  ------------------------------------------------------------------------
  

Changed:
  U   Zope3/trunk/src/zope/publisher/http.py
  U   Zope3/trunk/src/zope/publisher/tests/test_http.py

-=-
Modified: Zope3/trunk/src/zope/publisher/http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/http.py	2004-12-19 11:08:32 UTC (rev 28649)
+++ Zope3/trunk/src/zope/publisher/http.py	2004-12-19 11:38:03 UTC (rev 28650)
@@ -884,8 +884,12 @@
         after beginning stream-oriented output.
 
         """
-        self.output(string)
+        if not self._wrote_headers:
+            self.outputHeaders()
+            self._wrote_headers = True
 
+        self._outstream.write(string)
+
     def output(self, data):
         """Output the data to the world. There are a couple of steps we have
         to do:
@@ -909,13 +913,9 @@
             data = self._encode(data)
             self._updateContentLength(data)
 
-        if not self._wrote_headers:
-            self.outputHeaders()
-            self._wrote_headers = True
+        self.write(data)
 
-        self._outstream.write(data)
 
-
     def outputBody(self):
         """Outputs the response body."""
         self.output(self._body)

Modified: Zope3/trunk/src/zope/publisher/tests/test_http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/tests/test_http.py	2004-12-19 11:08:32 UTC (rev 28649)
+++ Zope3/trunk/src/zope/publisher/tests/test_http.py	2004-12-19 11:38:03 UTC (rev 28650)
@@ -446,6 +446,24 @@
         response.outputBody()
         return self._parseResult(stream.getvalue())
 
+    def testWrite(self):
+        response, stream = self._createResponse()
+        data = 'a'*10
+        # We have to set all the headers ourself
+        response.setHeader('Content-Type', 'text/plain;charset=us-ascii')
+        response.setHeader('Content-Length', str(len(data)))
+
+        # Stream the data
+        for ch in data:
+            response.write(ch)
+
+        headers, body = self._parseResult(stream.getvalue())
+        # Check that the data have been written, and that the header
+        # has been preserved   
+        self.assertEqual(headers['Content-Type'], 'text/plain;charset=us-ascii')
+        self.assertEqual(headers['Content-Length'], str(len(data)))
+        self.assertEqual(body, data)
+
     def testContentLength(self):
         eq = self.failUnlessEqual
 



More information about the Zope3-Checkins mailing list