[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/publisher/
If the content-type was text/*,
HTTPRespnse.write re-set the content-length
Bjorn Tillenius
bjoti777 at student.liu.se
Sun Dec 19 06:08:32 EST 2004
Log message for revision 28649:
If the content-type was text/*, HTTPRespnse.write re-set the content-length
header to the first chunk of data.
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/publisher/http.py
U Zope3/branches/ZopeX3-3.0/src/zope/publisher/tests/test_http.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/publisher/http.py 2004-12-18 14:56:26 UTC (rev 28648)
+++ Zope3/branches/ZopeX3-3.0/src/zope/publisher/http.py 2004-12-19 11:08:32 UTC (rev 28649)
@@ -883,8 +883,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:
@@ -908,13 +912,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/branches/ZopeX3-3.0/src/zope/publisher/tests/test_http.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/publisher/tests/test_http.py 2004-12-18 14:56:26 UTC (rev 28648)
+++ Zope3/branches/ZopeX3-3.0/src/zope/publisher/tests/test_http.py 2004-12-19 11:08:32 UTC (rev 28649)
@@ -454,6 +454,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