WebSocket and regexp: cannot access matches
Created by: ey3ball
When adding a websocket using a regexp, it is not possible to conveniently get the matched url and / or capture groups, because the initial "request" object is not fully kept (only headers are provided).
Indeed,
When processing a simple get request we can :
server.get("/info/([a-f0-9-]*)", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request,
AsyncHttpServerResponse response) {
/* Extract requested UUID */
String uuid = request.getMatcher.group(1);
/* Process request ... */
}
}
But using a websocket :
server.websocket("/connect/([a-f0-9-]*)", new AsyncHttpSever.WebSocketRequestCallback() {
@Override
public void onConnected(WebSocket webSocket, RequestHeaders requestHeaders) {
/* request is not available, It is not possible to find the requested UUID here
* without re-processing requestHeaders manually */
}
}
Since a websocket is initially an HTTP request after all, maybe a more complete request object should be exposed ?