Who is supposed to be calculating the content-length header when using 
wsgiutils and paster to run a simple http server?

I have have gzip setup in a use-filter on a composit with paste#urlmap

I change GZipResponse.write to print the length of string s.

It prints 

compressed length 1319

But, having turned on debugging in httplib2, I see this:

reply: 'HTTP/1.0 200 OK\r\n'
header: Server: SimpleHTTP/0.6 Python/2.4.2
header: Date: Wed, 08 Nov 2006 16:39:26 GMT
header: Content-Type: application/binary
header: Accept-Ranges: bytes
header: Last-Modified: Wed, 08 Nov 2006 16:39:26 GMT
header: ETag: 1163003966.18
header: Content-Range: 0-6310/6311
header: Content-Length: 6311
header: content-encoding: gzip

I believe that 6311 is the non-compressed length.

I am using DataApp to return the data.

I guess DataApp sets the content-length, but gzipper needs to override that 
header.

--

So, I have hacked in a content-length header change in gzipper, but I doubt it 
will 
work if underlying app writes directly to the return channel. My understanding 
of 
how that works is pretty weak, so some smarter person than I will need to fix 
up 
this patch

Index: /usr/local/src/Paste/paste/gzipper.py
==============================================================
=====
--- /usr/local/src/Paste/paste/gzipper.py       (revision 5907)
+++ /usr/local/src/Paste/paste/gzipper.py       (working copy)
@@ -12,6 +12,7 @@
 
 import gzip
 from paste.response import header_value
+from paste.httpheaders import CONTENT_LENGTH
 
 try:
     from cStringIO import StringIO

@@ -47,8 +49,10 @@
         self.compress_level = compress_level
         self.buffer = StringIO()
         self.compressible = False
+        self.headers = None
 
     def gzip_start_response(self, status, headers, exc_info=None):
+        self.headers = headers
         ct = header_value(headers,'content-type')
         ce = header_value(headers,'content-encoding')
         self.compressible = False
@@ -66,6 +70,9 @@
         out.seek(0)
         s = out.getvalue()
         out.close()
+        if self.compressible and self.headers is not None:
+            CONTENT_LENGTH.update(self.headers, len(s))
+        
         return [s]
 
     def finish_response(self, app_iter):



-- 
Brad Clements,                [EMAIL PROTECTED]    (315)268-1000
http://www.murkworks.com                          
AOL-IM or SKYPE: BKClements



_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users

Reply via email to