async def handshake(
        self,
        origins: Optional[Sequence[Optional[Origin]]] = None,
        available_extensions: Optional[Sequence[ServerExtensionFactory]] = None,
        available_subprotocols: Optional[Sequence[Subprotocol]] = None,
        extra_headers: Optional[HeadersLikeOrCallable] = None,
    ) -> str:
        """
        Perform the server side of the opening handshake.

        If provided, ``origins`` is a list of acceptable HTTP Origin values.
        Include ``None`` if the lack of an origin is acceptable.

        If provided, ``available_extensions`` is a list of supported
        extensions in the order in which they should be used.

        If provided, ``available_subprotocols`` is a list of supported
        subprotocols in order of decreasing preference.

        If provided, ``extra_headers`` sets additional HTTP response headers.
        It can be a :class:`~websockets.http.Headers` instance, a
        :class:`~collections.abc.Mapping`, an iterable of ``(name, value)``
        pairs, or a callable taking the request path and headers in arguments
        and returning one of the above.

        Raise :exc:`~websockets.exceptions.InvalidHandshake` if the handshake
        fails.

        Return the path of the URI of the request.

        """
        path, request_headers = await self.read_http_request()

        # Hook for customizing request handling, for example checking
        # authentication or treating some paths as plain HTTP endpoints.
        early_response = self.process_request(path, request_headers)
        if isinstance(early_response, Awaitable):
            early_response = await early_response

        # Change the response to a 503 error if the server is shutting down.
        if not self.ws_server.is_serving():
            early_response = (
                http.HTTPStatus.SERVICE_UNAVAILABLE,
                [],
                b"Server is shutting down.\n",
            )

        if early_response is not None:
            raise AbortHandshake(*early_response)

        key = check_request(request_headers)

        self.origin = self.process_origin(request_headers, origins)

        extensions_header, self.extensions = self.process_extensions(
            request_headers, available_extensions
        )

        protocol_header = self.subprotocol = self.process_subprotocol(
            request_headers, available_subprotocols
        )

        response_headers = Headers()

        build_response(response_headers, key)

        if extensions_header is not None:
            response_headers["Sec-WebSocket-Extensions"] = extensions_header

        if protocol_header is not None:
            response_headers["Sec-WebSocket-Protocol"] = protocol_header

        if extra_headers is not None:
            if callable(extra_headers):
                extra_headers = extra_headers(path, self.request_headers)
            if isinstance(extra_headers, Headers):
                extra_headers = extra_headers.raw_items()
            elif isinstance(extra_headers, collections.abc.Mapping):
                extra_headers = extra_headers.items()
            for name, value in extra_headers:
                response_headers[name] = value

        response_headers.setdefault("Date", email.utils.formatdate(usegmt=True))
        response_headers.setdefault("Server", USER_AGENT)

        self.write_http_response(http.HTTPStatus.SWITCHING_PROTOCOLS, response_headers)

        self.connection_open()

        return path
async def handshake ( self , origins : Optional [ Sequence [ Optional [ Origin ] ] ] = None , available_extensions : Optional [ Sequence [ ServerExtensionFactory ] ] = None , available_subprotocols : Optional [ Sequence [ Subprotocol ] ] = None , extra_headers : Optional [ HeadersLikeOrCallable ] = None , ) -> str : path , request_headers = await self . read_http_request ( ) early_response = self . process_request ( path , request_headers ) if isinstance ( early_response , Awaitable ) : early_response = await early_response if not self . ws_server . is_serving ( ) : early_response = ( http . HTTPStatus . SERVICE_UNAVAILABLE , [ ] , b"Server is shutting down.\n" , ) if early_response is not None : raise AbortHandshake ( * early_response ) key = check_request ( request_headers ) self . origin = self . process_origin ( request_headers , origins ) extensions_header , self . extensions = self . process_extensions ( request_headers , available_extensions ) protocol_header = self . subprotocol = self . process_subprotocol ( request_headers , available_subprotocols ) response_headers = Headers ( ) build_response ( response_headers , key ) if extensions_header is not None : response_headers [ "Sec-WebSocket-Extensions" ] = extensions_header if protocol_header is not None : response_headers [ "Sec-WebSocket-Protocol" ] = protocol_header if extra_headers is not None : if callable ( extra_headers ) : extra_headers = extra_headers ( path , self . request_headers ) if isinstance ( extra_headers , Headers ) : extra_headers = extra_headers . raw_items ( ) elif isinstance ( extra_headers , collections . abc . Mapping ) : extra_headers = extra_headers . items ( ) for name , value in extra_headers : response_headers [ name ] = value response_headers . setdefault ( "Date" , email . utils . formatdate ( usegmt = True ) ) response_headers . setdefault ( "Server" , USER_AGENT ) self . write_http_response ( http . HTTPStatus . SWITCHING_PROTOCOLS , response_headers ) self . connection_open ( ) return path
Perform the server side of the opening handshake.

        If provided, ``origins`` is a list of acceptable HTTP Origin values.
        Include ``None`` if the lack of an origin is acceptable.

        If provided, ``available_extensions`` is a list of supported
        extensions in the order in which they should be used.

        If provided, ``available_subprotocols`` is a list of supported
        subprotocols in order of decreasing preference.

        If provided, ``extra_headers`` sets additional HTTP response headers.
        It can be a :class:`~websockets.http.Headers` instance, a
        :class:`~collections.abc.Mapping`, an iterable of ``(name, value)``
        pairs, or a callable taking the request path and headers in arguments
        and returning one of the above.

        Raise :exc:`~websockets.exceptions.InvalidHandshake` if the handshake
        fails.

        Return the path of the URI of the request.