Multiplexed connection's on_open method #24

Closed
Alerion opened this Issue Feb 7, 2012 · 1 comment

Comments

Projects
None yet
2 participants

Alerion commented Feb 7, 2012

For example we have two multiplexed connections:

class RouterConnection(tornadio2.conn.SocketConnection):
    __endpoints__ = {
        '/admin': AdminConnection,
        '/user': UserConnection
    }

We need authentication only for AdminConnection, butAdminConnection.on_open does not affect connection process. I mean returning False does not abort connection.

Alerion commented Feb 7, 2012

Maybe this will be usefull. Changed Session.connect_endpoint and little hack to pass query string arguments to virtual connection.

def connect_endpoint(self, url):
    """Connect endpoint from URL.

    `url`
        socket.io endpoint URL.
    """
    urldata = urlparse.urlparse(url)

    endpoint = urldata.path

    conn_class = self.conn.get_endpoint(endpoint)
    if conn_class is None:
        logging.error('There is no handler for endpoint %s' % endpoint)
        return

    conn = conn_class(self, endpoint)

    args = copy.copy(self.request_arguments)
    args.update(urlparse.parse_qs(urldata.query))
    info = ConnectionInfo(self.remote_ip, args, dict())

    result = conn.on_open(info)

    if result is not None and not result:
        return

    self.endpoints[endpoint] = conn
    self.send_message(proto.connect(endpoint))

@mrjoes mrjoes closed this in 955758d Feb 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment