Skip to content

Commit

Permalink
Fix HttpServer::isWebSocket to detect lowercase "upgrade" connection …
Browse files Browse the repository at this point in the history
…value (#594)

* Fix HttpServer::isWebSocket to detect lowercase "upgrade" connection value

The websocket library boost-beast sends the following http header:
'Connection: upgrade', while almost anything else uses:
'Connection: Upgrade'. Drogon used to only recognize the latter as
websocket request, now it recognizes both.

* Fix HttpServer::isWebSocket to detect case-insenstive "websocket"
upgrade value

This was a bug as previously, we only accepted the exact string
"websocket", although the standard specifies that it should be
case-insensetive.

Co-authored-by: VayuDev <vayudev@protonmail.com>
  • Loading branch information
VayuDev and VayuDev committed Oct 4, 2020
1 parent 3d9278c commit de0d793
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/src/HttpServer.cc
Expand Up @@ -105,8 +105,18 @@ static bool isWebSocket(const HttpRequestImplPtr &req)
if (headers.find("upgrade") == headers.end() ||
headers.find("connection") == headers.end())
return false;
if (req->getHeaderBy("connection").find("Upgrade") != std::string::npos &&
req->getHeaderBy("upgrade") == "websocket")
auto connectionField = req->getHeaderBy("connection");
std::transform(connectionField.begin(),
connectionField.end(),
connectionField.begin(),
tolower);
auto upgradeField = req->getHeaderBy("upgrade");
std::transform(upgradeField.begin(),
upgradeField.end(),
upgradeField.begin(),
tolower);
if (connectionField.find("upgrade") != std::string::npos &&
upgradeField == "websocket")
{
LOG_TRACE << "new websocket request";

Expand Down

0 comments on commit de0d793

Please sign in to comment.