public static function accept($request, $handler)
    {
        static::checkRequest($request);

        $webSocketAccept = base64_encode(
            sha1($request->getWebSocketKey().'258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)
        );

        $response = static::create('', self::HTTP_SWITCHING_PROTOCOLS);

        $response->header('Upgrade', 'websocket');
        $response->header('Connection', 'Upgrade');
        $response->header('Sec-WebSocket-Accept', $webSocketAccept);
        $response->header('Sec-WebSocket-Version', '13');

        // WebSocket connection to 'ws://127.0.0.1:9502/'
        // failed: Error during WebSocket handshake:
        // Response must not include 'Sec-WebSocket-Protocol' header if not present in request: websocket
        if ($webSocketProtocol = $request->getWebSocketProtocol()) {
            $response->header('Sec-WebSocket-Protocol', $webSocketProtocol);
        }

        if ($handler !== null) {
            $response->setHandler($handler);
        }

        return $response;
    }