Ändere WebSocket-Protokollnamen und verbessere Server-Logging
- Aktualisiere den Protokollnamen von "yourchat-protocol" auf "chat" für bessere Klarheit. - Füge WebSocket-spezifische Optionen hinzu, um Sicherheitspraktiken zu verbessern. - Ergänze Logging für HTTP-Anfragen, um den Upgrade-Prozess zu WebSocket zu verfolgen.
This commit is contained in:
@@ -17,7 +17,7 @@ SSLServer* SSLServer::_instance = nullptr;
|
||||
// Protocols array definition
|
||||
struct lws_protocols SSLServer::_protocols[] = {
|
||||
{
|
||||
"yourchat-protocol",
|
||||
"chat",
|
||||
SSLServer::wsCallback,
|
||||
sizeof(WebSocketUserData),
|
||||
4096
|
||||
@@ -110,6 +110,9 @@ void SSLServer::startServer() {
|
||||
std::cout << "[YourChat] WebSocket Server starting on port " << _port << " (no SSL)" << std::endl;
|
||||
}
|
||||
|
||||
// WebSocket-spezifische Optionen
|
||||
info.options |= LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
||||
|
||||
// Reduziere Log-Level um weniger Debug-Ausgaben zu haben
|
||||
setenv("LWS_LOG_LEVEL", "0", 1); // 0 = nur Fehler
|
||||
|
||||
@@ -159,8 +162,14 @@ int SSLServer::wsCallback(struct lws *wsi, enum lws_callback_reasons reason, voi
|
||||
switch (reason) {
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
std::cout << "[YourChat] WebSocket-Verbindung hergestellt" << std::endl;
|
||||
// Request callback when writable to send initial message
|
||||
lws_callback_on_writable(wsi);
|
||||
break;
|
||||
|
||||
case LWS_CALLBACK_HTTP:
|
||||
std::cout << "[YourChat] HTTP request received, upgrading to WebSocket" << std::endl;
|
||||
return 0;
|
||||
|
||||
case LWS_CALLBACK_RECEIVE: {
|
||||
std::string msg(reinterpret_cast<char*>(in), len);
|
||||
std::cout << "[YourChat] WebSocket-Nachricht empfangen: " << msg << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user