[Zope3-checkins] SVN: Zope3/trunk/ Merged from ZopeX3-3.0 branch:
Bjorn Tillenius
bjoti777 at student.liu.se
Sat Mar 19 19:38:34 EST 2005
Log message for revision 29589:
Merged from ZopeX3-3.0 branch:
------------------------------------------------------------------------
r29588 | BjornT | 2005-03-19 19:19:47 -0500 (l?\195?\182r, 19 mar 2005) | 3 lines
Don't unconditionally add Content-Length header in HTTPResponse.getHeaders().
Do it only in output(), where the size of the data is known.
------------------------------------------------------------------------
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/publisher/http.py
U Zope3/trunk/src/zope/publisher/tests/test_http.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-03-20 00:19:47 UTC (rev 29588)
+++ Zope3/trunk/doc/CHANGES.txt 2005-03-20 00:38:33 UTC (rev 29589)
@@ -633,6 +633,10 @@
- If the content-type was text/*, HTTPResponse.write re-set the
content-length header to the first chunk of data.
+
+ - Don't unconditionally add Content-Length header in
+ HTTPResponse.getHeaders(). Do it only in output(), where the
+ size of the data is known.
Much thanks to everyone who contributed to this release:
Modified: Zope3/trunk/src/zope/publisher/http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/http.py 2005-03-20 00:19:47 UTC (rev 29588)
+++ Zope3/trunk/src/zope/publisher/http.py 2005-03-20 00:38:33 UTC (rev 29589)
@@ -635,10 +635,6 @@
result = {}
headers = self._headers
- if (not ('content-length' in headers)
- and not ('transfer-encoding' in headers)):
- self._updateContentLength()
-
result["X-Powered-By"] = "Zope (www.zope.org), Python (www.python.org)"
for key, val in headers.items():
@@ -891,8 +887,9 @@
self._outstream.write(string)
def output(self, data):
- """Output the data to the world. There are a couple of steps we have
- to do:
+ """Output the data to the world.
+
+ There are a couple of steps we have to do:
1. Check that there is a character encoding for the data. If not,
choose UTF-8. Note that if the charset is None, this is a sign of a
@@ -905,6 +902,9 @@
3. If the content type is text-based, let's encode the data and send
it also out the door.
+
+ 4. Make sure that a Content-Length or Transfer-Encoding header is
+ present.
"""
if self._charset is None:
self.setCharset('utf-8')
@@ -912,6 +912,10 @@
if self.getHeader('content-type', '').startswith('text'):
data = self._encode(data)
self._updateContentLength(data)
+
+ if (not ('content-length' in self._headers)
+ and not ('transfer-encoding' in self._headers)):
+ self._updateContentLength()
self.write(data)
Modified: Zope3/trunk/src/zope/publisher/tests/test_http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/tests/test_http.py 2005-03-20 00:19:47 UTC (rev 29588)
+++ Zope3/trunk/src/zope/publisher/tests/test_http.py 2005-03-20 00:38:33 UTC (rev 29589)
@@ -464,6 +464,26 @@
self.assertEqual(headers['Content-Length'], str(len(data)))
self.assertEqual(body, data)
+ def testWrite_noContentLength(self):
+ response, stream = self._createResponse()
+ data = 'a'*10
+ # We have to set all the headers ourself, we choose not to provide a
+ # content-length header
+ response.setHeader('Content-Type', 'text/plain;charset=us-ascii')
+
+ # 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(body, data)
+
+ # Make sure that no Content-Length header was added
+ self.assert_('Content-Length' not in headers)
+
def testContentLength(self):
eq = self.failUnlessEqual
More information about the Zope3-Checkins
mailing list