'Figure out how long the response body is going to be by examining
headers and stuff.'

def allHeadersReceived(self):

    if (100 <= self.response.code < 200):
        log.msg('Ignoring    unexpected    {}    response'.format(self.response.code))
        self.connectionMade()
        del self.response
        return
    if ((self.response.code in self.NO_BODY_CODES) or (self.request.method == 'HEAD')):
        self.response.length = 0
        self._finished(self.clearLineBuffer())
        self.response._bodyDataFinished()
    else:
        transferEncodingHeaders = self.connHeaders.getRawHeaders('transfer-encoding')
        if transferEncodingHeaders:
            transferDecoder = self._transferDecoders[transferEncodingHeaders[0].lower()]
        else:
            contentLengthHeaders = self.connHeaders.getRawHeaders('content-length')
            if (contentLengthHeaders is None):
                contentLength = None
            elif (len(contentLengthHeaders) == 1):
                contentLength = int(contentLengthHeaders[0])
                self.response.length = contentLength
            else:
                raise ValueError(u'Too    many    Content-Length    headers;    response    is    invalid')
            if (contentLength == 0):
                self._finished(self.clearLineBuffer())
                transferDecoder = None
            else:
                transferDecoder = (lambda x, y: _IdentityTransferDecoder(contentLength, x, y))
        if (transferDecoder is None):
            self.response._bodyDataFinished()
        else:
            self.transport.pauseProducing()
            self.switchToBodyMode(transferDecoder(self.response._bodyDataReceived, self._finished))
    self._responseDeferred.callback(self.response)
    del self._responseDeferred
