Skip to content

Commit 0318549

Browse files
committed
allow overriding the handling of Non Websocket Connection by extending the class.
see Links2004#10
1 parent 516b104 commit 0318549

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/WebSocketsServer.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,10 @@ void WebSocketsServer::handleHeader(WSclient_t * client) {
489489
}
490490

491491
} else {
492-
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] no Websocket connection close.\n", client->num);
493-
client->tcp.write("HTTP/1.1 400 Bad Request\r\n"
494-
"Server: arduino-WebSocket-Server\r\n"
495-
"Content-Type: text/plain\r\n"
496-
"Content-Length: 32\r\n"
497-
"Connection: close\r\n"
498-
"Sec-WebSocket-Version: 13\r\n"
499-
"\r\n"
500-
"This is a Websocket server only!");
501-
clientDisconnect(client);
492+
handleNonWebsocketConnection(client);
502493
}
503494
}
504495
}
505496

497+
498+

src/WebSocketsServer.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ class WebSocketsServer: private WebSockets {
108108

109109
void handleHeader(WSclient_t * client);
110110

111+
/**
112+
* called if a non Websocket connection is comming in.
113+
* Note: can be overrided
114+
* @param client WSclient_t * ptr to the client struct
115+
*/
116+
virtual void handleNonWebsocketConnection(WSclient_t * client) {
117+
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] no Websocket connection close.\n", client->num);
118+
client->tcp.write("HTTP/1.1 400 Bad Request\r\n"
119+
"Server: arduino-WebSocket-Server\r\n"
120+
"Content-Type: text/plain\r\n"
121+
"Content-Length: 32\r\n"
122+
"Connection: close\r\n"
123+
"Sec-WebSocket-Version: 13\r\n"
124+
"\r\n"
125+
"This is a Websocket server only!");
126+
clientDisconnect(client);
127+
}
128+
111129
};
112130

113131

0 commit comments

Comments
 (0)