netty-socketio
netty-socketio copied to clipboard
reuse data from AuthorizationListener
hi, i want to set data in AuthorizationListener then use the data in EventListener
so i don't have to decode token twice or more
what should i do ? thanks
you can use the threadlocal 🤓
well,threadlocal is unsafe in threadpool
A workaround is to use the HttpHeaders in the handshake data. It doesn't look elegant but works.
AuthorizationListener
handshakeData.getHttpHeaders().add('YOUR_TOKEN_KEY', 'TOKEN_VALUE')
EventListener
public void onData(SocketIOClient client, MessagePayload data, AckRequest ackSender) {
// fetch token from http headers in the handshake data
final String token = client.getHandshakeData().getHttpHeaders().get('YOUR_TOKEN_KEY');
// ...
}