[Twisted-Python] web2: http Content-Length header

Pieter Grimmerink mailinglists at grimmerink.nl
Wed Dec 6 12:39:40 EST 2006

On Wednesday 06 December 2006 17:23, James Y Knight wrote:
> You're supposed to get the length from the stream object.
> stream.length is an integer if the content length is known, and None
> if it is not known.

But stream.length is always None, even though the Content-Length is 

Pasted below is an example which demonstrates what I'm doing.
This is the response I'm getting:

<twisted.web2.http.Response code=302, streamlen=None>

And this is the response, when I add the line

self.stream.length = self.length

in twisted/web2/client/http.py, line 168:

<twisted.web2.http.Response code=302, streamlen=228>

Rgds, Pieter


from twisted.internet import protocol
from twisted.web2 import stream as stream_mod, http, http_headers, 
from twisted.web2.client.http import ClientRequest, HTTPClientProtocol

def testConn(host):
    from twisted.internet import reactor
    d = protocol.ClientCreator(reactor, HTTPClientProtocol).connectTCP(host, 
    def gotResp(resp):
        def print_(n):
            print "DATA"
        def printdone(n):
            print "DONE"
        print "GOT RESPONSE %s" % resp
        stream_mod.readStream(resp.stream, print_).addCallback(printdone)
    def sendReqs(proto):
        proto.submitRequest(ClientRequest("GET", "/index.html", 
{'Host':host}, None)).addCallback(gotResp)
    del d


More information about the Twisted-Python mailing list