Merge pull request #532 from oatpp/fix_connection_upgrade_sequence

HttpProcessor: Fix connection upgrade sequence.
This commit is contained in:
Leonid Stryzhevskyi 2021-12-17 04:00:58 +02:00 committed by GitHub
commit d06a98dfc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -190,17 +190,8 @@ HttpProcessor::ConnectionState HttpProcessor::processNextRequest(ProcessingResou
response->putHeaderIfNotExists(protocol::http::Header::CONNECTION, protocol::http::Header::Value::CONNECTION_CLOSE);
break;
case ConnectionState::DELEGATED: {
auto handler = response->getConnectionUpgradeHandler();
if(handler) {
handler->handleConnection(resources.connection, response->getConnectionUpgradeParameters());
connectionState = ConnectionState::DELEGATED;
} else {
OATPP_LOGW("[oatpp::web::server::HttpProcessor::processNextRequest()]", "Warning. ConnectionUpgradeHandler not set!");
connectionState = ConnectionState::CLOSING;
}
default:
break;
}
}
@ -211,6 +202,18 @@ HttpProcessor::ConnectionState HttpProcessor::processNextRequest(ProcessingResou
response->send(resources.connection.object.get(), &resources.headersOutBuffer, contentEncoderProvider.get());
/* Delegate connection handling to another handler only after the response is sent to the client */
if(connectionState == ConnectionState::DELEGATED) {
auto handler = response->getConnectionUpgradeHandler();
if(handler) {
handler->handleConnection(resources.connection, response->getConnectionUpgradeParameters());
connectionState = ConnectionState::DELEGATED;
} else {
OATPP_LOGW("[oatpp::web::server::HttpProcessor::processNextRequest()]", "Warning. ConnectionUpgradeHandler not set!");
connectionState = ConnectionState::CLOSING;
}
}
return connectionState;
}
@ -370,17 +373,8 @@ HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::onResponseFormed() {
m_currentResponse->putHeaderIfNotExists(protocol::http::Header::CONNECTION, protocol::http::Header::Value::CONNECTION_CLOSE);
break;
case ConnectionState::DELEGATED: {
auto handler = m_currentResponse->getConnectionUpgradeHandler();
if(handler) {
handler->handleConnection(m_connection, m_currentResponse->getConnectionUpgradeParameters());
m_connectionState = ConnectionState::DELEGATED;
} else {
OATPP_LOGW("[oatpp::web::server::HttpProcessor::Coroutine::onResponseFormed()]", "Warning. ConnectionUpgradeHandler not set!");
m_connectionState = ConnectionState::CLOSING;
}
default:
break;
}
}
@ -393,9 +387,27 @@ HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::onResponseFormed() {
}
HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::onRequestDone() {
if(m_connectionState == ConnectionState::ALIVE) {
return yieldTo(&HttpProcessor::Coroutine::parseHeaders);
switch (m_connectionState) {
case ConnectionState::ALIVE:
return yieldTo(&HttpProcessor::Coroutine::parseHeaders);
/* Delegate connection handling to another handler only after the response is sent to the client */
case ConnectionState::DELEGATED: {
auto handler = m_currentResponse->getConnectionUpgradeHandler();
if(handler) {
handler->handleConnection(m_connection, m_currentResponse->getConnectionUpgradeParameters());
m_connectionState = ConnectionState::DELEGATED;
} else {
OATPP_LOGW("[oatpp::web::server::HttpProcessor::Coroutine::onResponseFormed()]", "Warning. ConnectionUpgradeHandler not set!");
m_connectionState = ConnectionState::CLOSING;
}
break;
}
default:
break;
}
return finish();