use of reactor.netty.http.websocket.WebsocketOutbound in project reactor-netty by reactor.
the class WebsocketTest method doTestIssue970.
private void doTestIssue970(boolean compress) {
disposableServer = createServer().handle((req, res) -> res.sendWebsocket((in, out) -> out.sendString(Mono.just("test")), WebsocketServerSpec.builder().compress(compress).build())).bindNow();
AtomicBoolean clientHandler = new AtomicBoolean();
HttpClient client = createClient(disposableServer::address);
String perMessageDeflateEncoder = "io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateEncoder";
BiFunction<WebsocketInbound, WebsocketOutbound, Mono<Tuple2<String, String>>> receiver = (in, out) -> {
in.withConnection(conn -> clientHandler.set(conn.channel().pipeline().get(perMessageDeflateEncoder) != null));
String header = in.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS);
return in.receive().aggregate().asString().zipWith(Mono.just(header == null ? "null" : header));
};
Predicate<Tuple2<String, String>> predicate = t -> "test".equals(t.getT1()) && "null".equals(t.getT2());
StepVerifier.create(client.websocket().uri("/").handle(receiver)).expectNextMatches(predicate).expectComplete().verify(Duration.ofSeconds(30));
assertThat(clientHandler.get()).isFalse();
if (compress) {
predicate = t -> "test".equals(t.getT1()) && !"null".equals(t.getT2());
}
StepVerifier.create(client.websocket(WebsocketClientSpec.builder().compress(compress).build()).uri("/").handle(receiver)).expectNextMatches(predicate).expectComplete().verify(Duration.ofSeconds(30));
assertThat(clientHandler.get()).isEqualTo(compress);
}
Aggregations