[Twisted-Python] gzip with web

William Dode wilk-ml at flibuste.net
Sat Mar 8 16:11:15 EST 2003

William Dode <wilk-ml at flibuste.net> writes:

> hi,
> I convert a cgi site in twisted. On the server, the script run 10x
> faster ! but my users doesn't understand why i'm so happy since the see
> the page less quickly... I think it's because apache use mod_gzip. 
> How can i send the content with gzip ?

I answer to me...
        encoding = request.getHeader("accept-encoding")
        if encoding and encoding.find("gzip")>=0:
            import cStringIO,gzip
            zbuf = cStringIO.StringIO()
            zfile = gzip.GzipFile(None, 'wb', 9, zbuf)
            return zbuf.getvalue()
            return content

It works, i'm right ?

William Dode - http://flibuste.net

More information about the Twisted-Python mailing list