How to use the websockets.handshake.build_response function in websockets

To help you get started, we’ve selected a few websockets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aaugustin / websockets / tests / test_client_server.py View on Github external
def wrong_build_response(headers, key):
            return build_response(headers, "42")
github housleyjk / aiopyramid / aiopyramid / websocket / config / gunicorn.py View on Github external
self.status_int = 101

        http_1_1 = environ['SERVER_PROTOCOL'] == 'HTTP/1.1'

        def get_header(k):
            key_map = {k.upper(): k for k in environ}
            return environ[key_map['HTTP_' + k.upper().replace('-', '_')]]

        key = websockets.handshake.check_request(get_header)

        if not http_1_1 or key is None:
            self.status_int = 400
            self.content = "Invalid WebSocket handshake.\n"
        else:
            set_header = self.headers.__setitem__
            websockets.handshake.build_response(set_header, key)
            self.app_iter = HandshakeInterator(self.app_iter)
            self.app_iter.close = switch_protocols
github aaugustin / django-c10k-demo / c10ktools / http / websockets.py View on Github external
def __init__(self, environ, switch_protocols):
        super().__init__()

        http_1_1 = environ['SERVER_PROTOCOL'] == 'HTTP/1.1'
        get_header = lambda k: environ['HTTP_' + k.upper().replace('-', '_')]
        key = handshake.check_request(get_header)

        if not http_1_1 or key is None:
            self.status_code = 400
            self.content = "Invalid WebSocket handshake.\n"
        else:
            self._headers = {}                  # Reset headers (private API!)
            set_header = self.__setitem__
            handshake.build_response(set_header, key)
            self.close = switch_protocols