Alex Rivera | Logout

Twisted http gzip support

Asked 2011-03-25T04:13:12.260
11

As far as I could tell, Twisted doesn't support sending and receiving gzip information with HTTP: http://twistedmatrix.com/trac/ticket/104

Google seems to confirm it, since I couldn't find any mention of it the documentation. My question is whether I'm right about this, or if this has changed?

Edit
Report

1 Answer

7

This is now possible using Resource Encoders. Quoting from that link:

from twisted.web.server import Site, GzipEncoderFactory
from twisted.web.resource import Resource, EncodingResourceWrapper
from twisted.internet import reactor

class Simple(Resource):
    isLeaf = True
    def render_GET(self, request):
        return "<html>Hello, world!</html>"

resource = Simple()
wrapped = EncodingResourceWrapper(resource, [GzipEncoderFactory()])
site = Site(wrapped)
reactor.listenTCP(8080, site)
reactor.run()

See the link for more information. The ticket in the question is now closed as well.

answered 2013-03-04T18:35:33.370

Your Answer