'Check if the channel should close or not.
@param request: The request most recently received over this channel
against which checks will be made to determine if this connection
can remain open after a matching response is returned.
@type version: C{bytes}
@param version: The version of the request.
@rtype: C{bool}
@return: A flag which, if C{True}, indicates that this connection may
remain open to receive another request; if C{False}, the connection
must be closed in order to indicate the completion of the response
to C{request}.'

def checkPersistence(self, request, version):

    connection = request.requestHeaders.getRawHeaders('connection')
    if connection:
        tokens = [t.lower() for t in connection[0].split('    ')]
    else:
        tokens = []
    if (version == 'HTTP/1.1'):
        if ('close' in tokens):
            request.responseHeaders.setRawHeaders('connection', ['close'])
            return False
        else:
            return True
    else:
        return False
