[Zope3-checkins] CVS: Zope3/src/zope/publisher - http.py:1.46

Dmitry Vasiliev dima at hlabs.spb.ru
Fri Mar 26 09:56:25 EST 2004


Update of /cvs-repository/Zope3/src/zope/publisher
In directory cvs.zope.org:/tmp/cvs-serv7120/src/zope/publisher

Modified Files:
	http.py 
Log Message:
Fix for Content-Length


=== Zope3/src/zope/publisher/http.py 1.45 => 1.46 ===
--- Zope3/src/zope/publisher/http.py:1.45	Sat Mar 20 11:27:18 2004
+++ Zope3/src/zope/publisher/http.py	Fri Mar 26 09:56:22 2004
@@ -845,8 +845,11 @@
         return self.__class__(self._outstream,
                               self._header_output)
 
-    def _updateContentLength(self):
-        blen = str(len(self._body))
+    def _updateContentLength(self, data=None):
+        if data is None:
+            blen = str(len(self._body))
+        else:
+            blen = str(len(data))
         if blen.endswith('L'):
             blen = blen[:-1]
         self.setHeader('content-length', blen)
@@ -945,7 +948,8 @@
         computation of a response to proceed.
 
         The published object should first set any output headers or
-        cookies on the response object.
+        cookies on the response object and encode the string into
+        appropriate encoding.
 
         Note that published objects must not generate any errors
         after beginning stream-oriented output.
@@ -971,13 +975,15 @@
         """
         if self._charset is None:
             self.setCharset('utf-8')
-        
-        if not self._wrote_headers:
-            self.outputHeaders()
-            self._wrote_headers = True
 
         if self.getHeader('content-type', '').startswith('text'):
             data = self._encode(data)
+            # TODO: Need a test case
+            self._updateContentLength(data)
+
+        if not self._wrote_headers:
+            self.outputHeaders()
+            self._wrote_headers = True
 
         self._outstream.write(data)
 




More information about the Zope3-Checkins mailing list