Open vsaksonova opened 6 years ago
SocketIOChannelInitializer initializer = new SocketIOChannelInitializer();
Field encoderHandlerField = SocketIOChannelInitializer.class.getDeclaredField("encoderHandler");
encoderHandlerField.setAccessible(true);
Configuration configuration = server.getConfiguration();
WxEncoderHandler encodeHandler = new WxEncoderHandler(configuration, new PacketEncoder(configuration, configuration.getJsonSupport()));
server.setPipelineFactory(initializer);
server.start();
encoderHandlerField.set(initializer, encodeHandler);
@Sharable
public class WxEncoderHandler extends EncoderHandler {
private void sendMessage(HttpMessage msg, Channel channel, ByteBuf out, HttpResponse res, ChannelPromise promise) {
res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, "Origin, Authorization, Cookie, Accept, X-Requested-With, Last-Modified, Content-Type, io");
// ...
}
Reassign the encoderHandler
field of SocketIOChannelInitializer can work, but a little ugly...
I'm using netty-socketio on a java server side. A js client is using socketio.
The client can successfully connect and receive events unless it adds extraheaders (using polling) on connection. We want to use headers to pass tokens for authorization. The error is
If I understand correctly, I have to allow these headers on the server, but I cannot find the way. Already thought extra headers are not supported by netty-socketio.
Can anybody help?