Ejemplo n.º 1
0
    def handle_upgrade(self):
        """Completes the upgrade request sent by the browser

        Sends the headers required to set up to websocket connection back to
        the browser and then hands off to :meth:`handle_websocket`.

        See [websocket_protocol]_

        :returns: :exc:`webob.exc.HTTPBadRequest` if handshake fails
        """
        #from nose.tools import set_trace; set_trace()
        try:
            v, handshake_reply = websocket_handshake(self.request.headers)
        except HandShakeFailed:
            _, val, _ = sys.exc_info()
            response = HTTPBadRequest(headers=dict(Connection='Close'),
                                      body='Upgrade negotiation failed:\n\t%s\n%s' % \
                                                (val, self.request.headers))
            return response
        sock = self.environ['eventlet.input'].get_socket()
        sock.sendall(handshake_reply)
        if v < 2:
            return self.handle_websocket(v76WebSocket(self.sock, self.environ))
        else:
            return self.handle_websocket(WebSocket(self.sock, self.environ))
Ejemplo n.º 2
0
    def handle_upgrade(self):
        """Completes the upgrade request sent by the browser

        Sends the headers required to set up to websocket connection back to
        the browser and then hands off to :meth:`handle_websocket`.

        See [websocket_protocol]_

        :returns: :exc:`webob.exc.HTTPBadRequest` if handshake fails
        """
        #from nose.tools import set_trace; set_trace()
        try:
            v, handshake_reply = websocket_handshake(self.request.headers)
        except HandShakeFailed:
            _, val, _ = sys.exc_info()
            response = HTTPBadRequest(headers=dict(Connection='Close'),
                                      body='Upgrade negotiation failed:\n\t%s\n%s' % \
                                                (val, self.request.headers))
            return response
        sock = self.environ['eventlet.input'].get_socket()
        sock.sendall(handshake_reply)
        if v < 2:
            return self.handle_websocket(v76WebSocket(self.sock, self.environ))
        else:
            return self.handle_websocket(WebSocket(self.sock, self.environ))
Ejemplo n.º 3
0
def equals(headers, expected):
    eq_(hs.websocket_handshake(headers), expected)