public function handshake(Request $request, Response $response): array
    {
        try {
            $path = $request->getUri()->getPath();
            list($className,) = $this->getHandler($path);
        } catch (\Throwable $e) {
            /* @var ErrorHandler $errorHandler */
            // $errorHandler = \bean(ErrorHandler::class);
            // $response = $errorHandler->handle($e);
            if ($e instanceof WsRouteException) {
                return [
                    HandlerInterface::HANDSHAKE_FAIL,
                    $response->withStatus(404)->withAddedHeader('Failure-Reason', 'Route not found')
                ];
            }

            // other error
            throw $e;
        }

        /** @var HandlerInterface $handler */
        $handler = \bean($className);

        if (!\method_exists($handler, 'checkHandshake')) {
            return [
                HandlerInterface::HANDSHAKE_OK,
                $response->withAddedHeader('swoft-ws-handshake', 'auto')
            ];
        }

        return $handler->checkHandshake($request, $response);
    }
public function handshake(Request $request, Response $response): array
    {
        try {
            $path = $request->getUri()->getPath();
            list($className,) = $this->getHandler($path);
        } catch (\Throwable $e) {
            /* @var ErrorHandler $errorHandler */
            // $errorHandler = \bean(ErrorHandler::class);
            // $response = $errorHandler->handle($e);
            if ($e instanceof WsRouteException) {
                return [
                    HandlerInterface::HANDSHAKE_FAIL,
                    $response->withStatus(404)->withAddedHeader('Failure-Reason', 'Route not found')
                ];
            }

            // other error
            throw $e;
        }

        /** @var HandlerInterface $handler */
        $handler = \bean($className);

        if (!\method_exists($handler, 'checkHandshake')) {
            return [
                HandlerInterface::HANDSHAKE_OK,
                $response->withAddedHeader('swoft-ws-handshake', 'auto')
            ];
        }

        return $handler->checkHandshake($request, $response);
    }
public function handshake ( Request $ request , Response $ response ) : array { try { $ path = $ request -> getUri ( ) -> getPath ( ) ; list ( $ className , ) = $ this -> getHandler ( $ path ) ; } catch ( \ Throwable $ e ) { /* @var ErrorHandler $errorHandler */ // $errorHandler = \bean(ErrorHandler::class); // $response = $errorHandler->handle($e); if ( $ e instanceof WsRouteException ) { return [ HandlerInterface :: HANDSHAKE_FAIL , $ response -> withStatus ( 404 ) -> withAddedHeader ( 'Failure-Reason' , 'Route not found' ) ] ; } // other error throw $ e ; } /** @var HandlerInterface $handler */ $ handler = \ bean ( $ className ) ; if ( ! \ method_exists ( $ handler , 'checkHandshake' ) ) { return [ HandlerInterface :: HANDSHAKE_OK , $ response -> withAddedHeader ( 'swoft-ws-handshake' , 'auto' ) ] ; } return $ handler -> checkHandshake ( $ request , $ response ) ; }
dispatch handshake request
@param Request $request
@param Response $response
@return array eg. [status, response]
@throws \Swoft\WebSocket\Server\Exception\WsRouteException
@throws \InvalidArgumentException
@throws \Throwable
dispatch handshake request