Skip to content

Commit

Permalink
fix(qq): πŸ› fix websocket connection with invalid path
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Oct 2, 2024
1 parent c11e134 commit 92d7208
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,29 @@ public QQWsServer(String host, Integer port, String validResourcePath, Queue<QQE

@Override
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
logger.info("QQ WebSocket connection opened at [{}], path:[{}]", webSocket.getLocalSocketAddress(), clientHandshake.getResourceDescriptor());
if (validResourcePath.equals(clientHandshake.getResourceDescriptor())) {
InetSocketAddress remoteSocketAddress = webSocket.getRemoteSocketAddress();
String resourceDescriptor = webSocket.getResourceDescriptor();
if (validResourcePath.equals(resourceDescriptor)) {
clients.add(webSocket);
logger.info(
"QQ WebSocket client at [{}] connection established with path [{}]",
remoteSocketAddress,
resourceDescriptor
);
} else {
webSocket.close();
logger.warn(
"QQ WebSocket client at [{}] connection established with invalid path [{}], connection closed",
remoteSocketAddress,
resourceDescriptor
);
}
}

@Override
public void onClose(WebSocket webSocket, int i, String s, boolean b) {
logger.info("QQ WebSocket connection closed");
logger.info("QQ WebSocket client at [{}] connection closed", webSocket.getRemoteSocketAddress());
clients.remove(webSocket);
}

@Override
Expand Down

0 comments on commit 92d7208

Please # to comment.