예제 #1
0
void WebSocketFramer::acceptRequest(http::Request& request, http::Response& response)
{
	if (util::icompare(request.get("Connection", ""), "upgrade") == 0 && 
		util::icompare(request.get("Upgrade", ""), "websocket") == 0) {
		std::string version = request.get("Sec-WebSocket-Version", "");
		if (version.empty()) throw std::runtime_error("WebSocket error: Missing Sec-WebSocket-Version in handshake request"); //, ws::ErrorHandshakeNoVersion
		if (version != ws::ProtocolVersion) throw std::runtime_error("WebSocket error: Unsupported WebSocket version requested: " + version); //, ws::ErrorHandshakeUnsupportedVersion
		std::string key = util::trim(request.get("Sec-WebSocket-Key", ""));
		if (key.empty()) throw std::runtime_error("WebSocket error: Missing Sec-WebSocket-Key in handshake request"); //, ws::ErrorHandshakeNoKey
		
		response.setStatus(http::StatusCode::SwitchingProtocols);
		response.set("Upgrade", "websocket");
		response.set("Connection", "Upgrade");
		response.set("Sec-WebSocket-Accept", computeAccept(key));

		// Set headerState 2 since the handshake was accepted.
		_headerState = 2;
	}
	else throw std::runtime_error("WebSocket error: No WebSocket handshake"); //, ws::ErrorNoHandshake
}
예제 #2
0
void Authenticator::updateAuthInfo(http::Request& request)
{
    if (request.has("Authorization")) {
        const std::string& authorization = request.get("Authorization");

        if (isBasicCredentials(authorization)) {
            BasicAuthenticator(_username, _password).authenticate(request);
        }
        // else if (isDigestCredentials(authorization))
        //    ; // TODO
    }
}
예제 #3
0
bool hasProxyDigestCredentials(const http::Request& request)
{
    return request.has("Proxy-Authorization") &&
           isDigestCredentials(request.get("Proxy-Authorization"));
}
예제 #4
0
bool hasBasicCredentials(const http::Request& request)
{
    return request.has("Authorization") &&
           isBasicCredentials(request.get("Authorization"));
}