private function verifyUpgradeRequest(HttpRequest $request)
    {
        $this->logger->debug("Attempting to switch protocols (checking preconditions per RFC)");

        //That "ifology" is ugly, but I don't have better idea to perform checks

        //Check request to conform with RFC 6455 [see page 16]
        if ($request->getMethod() !== "GET") {
            throw new HttpException("Cannot upgrade to WebSocket - invalid method", HttpCode::METHOD_NOT_ALLOWED);
        }

        if ($request->getProtocolVersion() != 1.1) {
            throw new HttpException("Cannot upgrade to WebSockets - http version not supported",
                HttpCode::VERSION_NOT_SUPPORTED);
        }

        //Intentionally skipped host & origin validation here

        if (strtolower($request->getHeader("upgrade")) !== "websocket") {
            throw new HttpException("Cannot upgrade to WebSockets - invalid upgrade header", HttpCode::BAD_REQUEST);
        }

        if (strpos(strtolower($request->getHeader("connection")), "upgrade") === false) {
            throw new HttpException("Cannot upgrade to WebSockets - invalid connection header", HttpCode::BAD_REQUEST);
        }

        $wsNoonce = base64_decode($request->getHeader("sec-websocket-key"));
        if (strlen($wsNoonce) !== 16) {
            throw new HttpException("Cannot upgrade to WebSockets - invalid key", HttpCode::BAD_REQUEST);
        }

        if (strtolower($request->getHeader("sec-websocket-version")) != self::SUPPORTED_WEBSOCKET_VERSION) {
            throw new HttpException("Cannot upgrade to WebSockets - version not supported", HttpCode::UPGRADE_REQUIRED,
                array("Sec-WebSocket-Version" => self::SUPPORTED_WEBSOCKET_VERSION));
        }

        $this->logger->debug("RFC check OK");
    }