Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/test/java/io/vertx/tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.Closeable;
import java.util.concurrent.*;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
Expand Down Expand Up @@ -72,6 +73,10 @@ protected Closeable startProxy(SocketAddress backend) {
}

protected Closeable startProxy(Consumer<HttpProxy> config) {
return startProxy(UnaryOperator.identity(), config);
}

protected Closeable startProxy(UnaryOperator<HttpServerOptions> proxyOptionsConfig, Consumer<HttpProxy> config) {
CompletableFuture<Closeable> res = new CompletableFuture<>();
vertx.deployVerticle(new AbstractVerticle() {
HttpClient proxyClient;
Expand All @@ -80,7 +85,7 @@ protected Closeable startProxy(Consumer<HttpProxy> config) {
@Override
public void start(Promise<Void> startFuture) {
proxyClient = vertx.createHttpClient(new HttpClientOptions(clientOptions));
proxyServer = vertx.createHttpServer(new HttpServerOptions(serverOptions));
proxyServer = vertx.createHttpServer(proxyOptionsConfig.apply(new HttpServerOptions(serverOptions)));
proxy = HttpProxy.reverseProxy(proxyOptions, proxyClient);
config.accept(proxy);
proxyServer.requestHandler(proxy);
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/io/vertx/tests/WebSocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,42 @@ public Future<ProxyResponse> handleProxyRequest(ProxyContext context) {
});
}));
}

@Test
public void testWebSocketExtensionsNegotiatedBetweenClientAndBackend(TestContext ctx) {
Async async = ctx.async();
HttpServerOptions backendOptions = new HttpServerOptions().setPort(8081).setHost("localhost")
.setPerFrameWebSocketCompressionSupported(false) // Disable extension in the backend
.setPerMessageWebSocketCompressionSupported(false); // Disable extension in the backend
SocketAddress backend = startHttpBackend(ctx, backendOptions, req -> {
ctx.assertTrue(req.headers().contains("sec-websocket-extensions"));
Future<ServerWebSocket> fut = req.toWebSocket();
fut.onComplete(ctx.asyncAssertSuccess(ws -> {
ws.handler(buff -> ws.writeTextMessage(buff.toString()));
ws.closeHandler(v -> {
async.complete();
});
}));
});
startProxy(proxyServerOptions -> {
return proxyServerOptions
.setPerFrameWebSocketCompressionSupported(true) // Enable extension in the proxy
.setPerMessageWebSocketCompressionSupported(true); // Enable extension in the proxy
}, httpProxy -> httpProxy.origin(backend));
wsClient = vertx.createWebSocketClient(new WebSocketClientOptions()
.setTryUsePerFrameCompression(true) // Enable extension in the client
.setTryUsePerMessageCompression(true)); // Enable extension in the client
WebSocketConnectOptions options = new WebSocketConnectOptions()
.setPort(8080)
.setHost("localhost")
.setURI("/ws");
wsClient.connect(options).onComplete(ctx.asyncAssertSuccess(ws -> {
ctx.assertFalse(ws.headers().contains("sec-websocket-extensions"), "Expected extensions to be declined");
ws.textMessageHandler(msg -> {
ctx.assertEquals("hello", msg);
ws.close();
});
ws.writeTextMessage("hello");
}));
}
}