allow overriding the handling of Non Websocket Connection by extending the class.

see #10
This commit is contained in:
Markus Sattler
2015-08-08 19:54:36 +02:00
parent 516b1047f8
commit 03185498e8
2 changed files with 21 additions and 10 deletions

View File

@ -489,17 +489,10 @@ void WebSocketsServer::handleHeader(WSclient_t * client) {
}
} else {
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] no Websocket connection close.\n", client->num);
client->tcp.write("HTTP/1.1 400 Bad Request\r\n"
"Server: arduino-WebSocket-Server\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 32\r\n"
"Connection: close\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
"This is a Websocket server only!");
clientDisconnect(client);
handleNonWebsocketConnection(client);
}
}
}

View File

@ -108,6 +108,24 @@ private:
void handleHeader(WSclient_t * client);
/**
* called if a non Websocket connection is comming in.
* Note: can be overrided
* @param client WSclient_t * ptr to the client struct
*/
virtual void handleNonWebsocketConnection(WSclient_t * client) {
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] no Websocket connection close.\n", client->num);
client->tcp.write("HTTP/1.1 400 Bad Request\r\n"
"Server: arduino-WebSocket-Server\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 32\r\n"
"Connection: close\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
"This is a Websocket server only!");
clientDisconnect(client);
}
};