'This function handles a CONNECT request.
The actions taken are:
- create a new socket,
- register the connection into the server,
- connect to the remote host,
- tell the client the connection is established,
- forward data between the client and the remote peer.'

def handle_connect(self, req):

    remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    remote.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    try:
        try:
            log.debug(thread.get_ident(), 'Connecting    to', req['address'])
            remote.connect(req['address'])
        except socket.error:
            (exception, value, traceback) = sys.exc_info()
            if (value[0] == ERR_CONNECTION_RESET_BY_PEER):
                raise Client_Connection_Closed((ERR_CONNECTION_RESET_BY_PEER, socket.errorTab[ERR_CONNECTION_RESET_BY_PEER]))
            else:
                raise Remote_Connection_Failed
        except:
            raise Remote_Connection_Failed
        try:
            self.answer_granted()
            self.forward(self.client_socketet, remote)
        except socket.error:
            raise Connection_Closed
    finally:
        remote.close()
