Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Prevent crash on WebSocket request to non-WebSocket node. #106

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/HTTPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,17 @@ void HTTPConnection::loop() {

// Finally, after the handshake is done, we create the WebsocketHandler and change the internal state.
if(websocketRequested) {
_wsHandler = ((WebsocketNode*)resolvedResource.getMatchingNode())->newHandler();
_wsHandler->initialize(this); // make websocket with this connection
_connectionState = STATE_WEBSOCKET;
HTTPNode *node = resolvedResource.getMatchingNode();

// Check for websocket request on non-websocket node:
if (node == nullptr || node->_nodeType != HTTPNodeType::WEBSOCKET) {
HTTPS_LOGW("Websocket request on non-websocket node rejected");
raiseError(404, "Not Found");
} else {
_wsHandler = ((WebsocketNode *) node)->newHandler();
_wsHandler->initialize(this); // make websocket with this connection
_connectionState = STATE_WEBSOCKET;
}
} else {
// Handling the request is done
HTTPS_LOGD("Handler function done, request complete");
Expand Down