A straightforward use of a series of request.write()s with a
request.finish() in the render_GET() method of a resource defaults to
chunked encoding. I can avoid the chunked encoding by computing the entire
response first using a StringIO (as shown below) and explicitly putting the
"Content-Length" header in myself.
Is this the best (or recommended) way to create such a response?
Thx - Tom
def render_GET(self, response):
output = StringIO.StringIO()
data = output.getvalue()
# Write the response data. "content-length" suppresses chunked coding
I was wondering about ways to mount different types of protocol handlers on
the same port. It looks like there will be new WebSocket support
implementing a websocket Site. We'll also have the existing HTTP Site.
Will they both be able to live on port 80? Is it important to be able to
In my own experiments, I've modified "portforward.py" to inspect an
incoming request and dispatch to one of two different servers mounted on
Unix-Domain sockets, depending on the request path in the header. It
looks something like the code below. This does a lot of copying of each
data packet, but seems to be effective.
Does anyone have a better suggestion for how to mount different protocol
handlers on the same port?
site1 = twisted.web.server.Site(...)
site2 = txws.WebSocketFactory(...)
# this routes requests on port 80 to one of the two sockets
reactor.listenTCP(80, InspectingProxyFactory("site1.sck", "site2.sck")