'I didn\'t want to override this, but there\'s no way around
it in order to support deferreds - CM
finalize this transaction - send output to the http channel'

def done(self, *arg, **kw):

    connection = http_server.get_header(http_server.CONNECTION, self.header)
    connection = connection.lower()
    close_it = 0
    wrap_in_chunking = 0
    globbing = 1
    if (self.version == '1.0'):
        if (connection == 'keep-alive'):
            if (not ('Content-Length' in self)):
                close_it = 1
            else:
                self['Connection'] = 'Keep-Alive'
        else:
            close_it = 1
    elif (self.version == '1.1'):
        if (connection == 'close'):
            close_it = 1
        elif (not ('Content-Length' in self)):
            if ('Transfer-Encoding' in self):
                if (not (self['Transfer-Encoding'] == 'chunked')):
                    close_it = 1
            elif self.use_chunked:
                self['Transfer-Encoding'] = 'chunked'
                wrap_in_chunking = 1
                globbing = 0
            else:
                close_it = 1
    elif (self.version is None):
        close_it = 1
    outgoing_header = producers.simple_producer(self.build_reply_header())
    if close_it:
        self['Connection'] = 'close'
    if wrap_in_chunking:
        outgoing_producer = deferring_chunked_producer(deferring_composite_producer(self.outgoing))
        outgoing_producer = deferring_composite_producer([outgoing_header, outgoing_producer])
    else:
        self.outgoing.insert(0, outgoing_header)
        outgoing_producer = deferring_composite_producer(self.outgoing)
    outgoing_producer = deferring_hooked_producer(outgoing_producer, self.log)
    if globbing:
        outgoing_producer = deferring_globbing_producer(outgoing_producer)
    self.channel.push_with_producer(outgoing_producer)
    self.channel.current_request = None
    if close_it:
        self.channel.close_when_done()
