Permalink
Browse files

Enable compression extension for websockets

  • Loading branch information...
SquidDev committed May 5, 2018
1 parent 2bb5ce5 commit 9809e147dd6f69fba59270e04bf787468c6fa880
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/main/java/dan200/computercraft/core/apis/http/WebsocketConnector.java
@@ -22,6 +22,7 @@
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
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.SslContextBuilder;
@@ -35,7 +36,7 @@
import java.util.Map;
import java.util.concurrent.Future;
/*
/**
* Provides functionality to verify and connect to a remote websocket.
*/
public final class WebsocketConnector
@@ -178,7 +179,7 @@ else if( scheme.equalsIgnoreCase( "wss" ) )
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 );
new Bootstrap()
@@ -191,7 +192,12 @@ protected void initChannel( SocketChannel ch ) throws Exception
{
ChannelPipeline p = ch.pipeline();
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 )

0 comments on commit 9809e14

Please sign in to comment.