Skip to content

Commit 4c2e97b

Browse files
committed
Enable compression extension for websockets
1 parent f17df15 commit 4c2e97b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/dan200/computercraft/core/apis/http/WebsocketConnector.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
2222
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
2323
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
24+
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
2425
import io.netty.handler.ssl.SslContext;
2526
import io.netty.handler.ssl.SslContextBuilder;
2627

@@ -34,7 +35,7 @@
3435
import java.util.Map;
3536
import java.util.concurrent.Future;
3637

37-
/*
38+
/**
3839
* Provides functionality to verify and connect to a remote websocket.
3940
*/
4041
public final class WebsocketConnector
@@ -177,7 +178,7 @@ public static Future<?> createConnector( final IAPIEnvironment environment, fina
177178
httpHeaders.add( header.getKey(), header.getValue() );
178179
}
179180

180-
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker( uri, WebSocketVersion.V13, null, false, httpHeaders );
181+
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker( uri, WebSocketVersion.V13, null, true, httpHeaders );
181182
final WebsocketConnection connection = new WebsocketConnection( environment, api, handshaker, address );
182183

183184
new Bootstrap()
@@ -190,7 +191,12 @@ protected void initChannel( SocketChannel ch ) throws Exception
190191
{
191192
ChannelPipeline p = ch.pipeline();
192193
if( ssl != null ) p.addLast( ssl.newHandler( ch.alloc(), uri.getHost(), port ) );
193-
p.addLast( new HttpClientCodec(), new HttpObjectAggregator( 8192 ), connection );
194+
p.addLast(
195+
new HttpClientCodec(),
196+
new HttpObjectAggregator( 8192 ),
197+
WebSocketClientCompressionHandler.INSTANCE,
198+
connection
199+
);
194200
}
195201
} )
196202
.remoteAddress( socketAddress )

0 commit comments

Comments
 (0)