1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-12 18:30:29 +00:00

Enable compression extension for websockets

This commit is contained in:
SquidDev 2018-05-05 08:33:31 +01:00
parent f17df15117
commit 4c2e97b1af

View File

@ -21,6 +21,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker; import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory; import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.codec.http.websocketx.WebSocketVersion;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.SslContextBuilder;
@ -34,7 +35,7 @@ import java.security.KeyStore;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Future; import java.util.concurrent.Future;
/* /**
* Provides functionality to verify and connect to a remote websocket. * Provides functionality to verify and connect to a remote websocket.
*/ */
public final class WebsocketConnector public final class WebsocketConnector
@ -177,7 +178,7 @@ public final class WebsocketConnector
httpHeaders.add( header.getKey(), header.getValue() ); httpHeaders.add( header.getKey(), header.getValue() );
} }
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker( uri, WebSocketVersion.V13, null, false, httpHeaders ); WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker( uri, WebSocketVersion.V13, null, true, httpHeaders );
final WebsocketConnection connection = new WebsocketConnection( environment, api, handshaker, address ); final WebsocketConnection connection = new WebsocketConnection( environment, api, handshaker, address );
new Bootstrap() new Bootstrap()
@ -190,7 +191,12 @@ public final class WebsocketConnector
{ {
ChannelPipeline p = ch.pipeline(); ChannelPipeline p = ch.pipeline();
if( ssl != null ) p.addLast( ssl.newHandler( ch.alloc(), uri.getHost(), port ) ); if( ssl != null ) p.addLast( ssl.newHandler( ch.alloc(), uri.getHost(), port ) );
p.addLast( new HttpClientCodec(), new HttpObjectAggregator( 8192 ), connection ); p.addLast(
new HttpClientCodec(),
new HttpObjectAggregator( 8192 ),
WebSocketClientCompressionHandler.INSTANCE,
connection
);
} }
} ) } )
.remoteAddress( socketAddress ) .remoteAddress( socketAddress )