Browse Source

Websocket compression support. #313

master
Nikita 10 years ago
parent
commit
4669698be5
  1. 25
      src/main/java/com/corundumstudio/socketio/SocketIOChannelInitializer.java

25
src/main/java/com/corundumstudio/socketio/SocketIOChannelInitializer.java

@ -15,16 +15,6 @@
*/ */
package com.corundumstudio.socketio; package com.corundumstudio.socketio;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.ssl.SslHandler;
import java.security.KeyStore; import java.security.KeyStore;
import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.KeyManagerFactory;
@ -56,9 +46,21 @@ import com.corundumstudio.socketio.store.pubsub.PubSubStore;
import com.corundumstudio.socketio.transport.PollingTransport; import com.corundumstudio.socketio.transport.PollingTransport;
import com.corundumstudio.socketio.transport.WebSocketTransport; import com.corundumstudio.socketio.transport.WebSocketTransport;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
import io.netty.handler.ssl.SslHandler;
public class SocketIOChannelInitializer extends ChannelInitializer<Channel> implements DisconnectableHub { public class SocketIOChannelInitializer extends ChannelInitializer<Channel> implements DisconnectableHub {
public static final String SOCKETIO_ENCODER = "socketioEncoder"; public static final String SOCKETIO_ENCODER = "socketioEncoder";
public static final String WEB_SOCKET_TRANSPORT_COMPRESSION = "webSocketTransportCompression";
public static final String WEB_SOCKET_TRANSPORT = "webSocketTransport"; public static final String WEB_SOCKET_TRANSPORT = "webSocketTransport";
public static final String WEB_SOCKET_AGGREGATOR = "webSocketAggregator"; public static final String WEB_SOCKET_AGGREGATOR = "webSocketAggregator";
public static final String XHR_POLLING_TRANSPORT = "xhrPollingTransport"; public static final String XHR_POLLING_TRANSPORT = "xhrPollingTransport";
@ -80,6 +82,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer<Channel> impl
private AuthorizeHandler authorizeHandler; private AuthorizeHandler authorizeHandler;
private PollingTransport xhrPollingTransport; private PollingTransport xhrPollingTransport;
private WebSocketTransport webSocketTransport; private WebSocketTransport webSocketTransport;
private WebSocketServerCompressionHandler webSocketTransportCompression = new WebSocketServerCompressionHandler();
private EncoderHandler encoderHandler; private EncoderHandler encoderHandler;
private WrongUrlHandler wrongUrlHandler; private WrongUrlHandler wrongUrlHandler;
@ -175,6 +178,8 @@ public class SocketIOChannelInitializer extends ChannelInitializer<Channel> impl
pipeline.addLast(AUTHORIZE_HANDLER, authorizeHandler); pipeline.addLast(AUTHORIZE_HANDLER, authorizeHandler);
pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport); pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport);
// TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved
pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler());
pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport); pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport);
pipeline.addLast(SOCKETIO_ENCODER, encoderHandler); pipeline.addLast(SOCKETIO_ENCODER, encoderHandler);

Loading…
Cancel
Save