use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method serverCompressionDefault.
@Test
public void serverCompressionDefault() throws Exception {
HttpServer server = HttpServer.create(0);
NettyContext nettyContext = server.newHandler((in, out) -> out.sendString(Mono.just("reply"))).block(Duration.ofMillis(10_000));
HttpClient client = HttpClient.create(o -> o.connectAddress(() -> address(nettyContext)));
HttpClientResponse resp = client.get("/test", req -> req.header("Accept-Encoding", "gzip")).block();
assertThat(resp.responseHeaders().get("content-encoding")).isNull();
String reply = resp.receive().asString().blockFirst();
Assert.assertEquals("reply", reply);
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method serverCompressionAlwaysEnabled.
@Test
public void serverCompressionAlwaysEnabled() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression(true));
NettyContext nettyContext = server.newHandler((in, out) -> out.sendString(Mono.just("reply"))).block(Duration.ofMillis(10_000));
// don't activate compression on the client options to avoid auto-handling (which removes the header)
HttpClient client = HttpClient.create(o -> o.connectAddress(() -> address(nettyContext)));
HttpClientResponse resp = // edit the header manually to attempt to trigger compression on server side
client.get("/test", req -> req.header("Accept-Encoding", "gzip")).block();
assertThat(resp.responseHeaders().get("content-encoding")).isEqualTo("gzip");
byte[] replyBuffer = resp.receive().aggregate().asByteArray().block();
assertThat(new String(replyBuffer)).isNotEqualTo("reply");
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(replyBuffer));
byte[] deflatedBuf = new byte[1024];
int readable = gis.read(deflatedBuf);
gis.close();
assertThat(readable).isGreaterThan(0);
String deflated = new String(deflatedBuf, 0, readable);
assertThat(deflated).isEqualTo("reply");
nettyContext.dispose();
nettyContext.onClose().block();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method compressionServerDefaultClientDefaultIsNone.
@Test
public void compressionServerDefaultClientDefaultIsNone() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0));
NettyContext nettyContext = server.newHandler((in, out) -> out.sendString(Mono.just("reply"))).block(Duration.ofMillis(10_000));
HttpClient client = HttpClient.create(o -> o.connectAddress(() -> address(nettyContext)));
HttpClientResponse resp = client.get("/test").block();
String reply = resp.receive().asString().blockFirst();
assertThat(resp.responseHeaders().get("Content-Encoding")).isNull();
assertThat(reply).isEqualTo("reply");
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method testIssue282.
@Test
public void testIssue282() {
NettyContext server = HttpServer.create(options -> options.compression(2048).port(0)).newHandler((req, res) -> res.sendString(Mono.just("testtesttesttesttest"))).block(Duration.ofSeconds(30));
Mono<String> response = HttpClient.create(server.address().getPort()).get("/").flatMap(res -> res.receive().aggregate().asString());
StepVerifier.create(response).expectNextMatches(s -> "testtesttesttesttest".equals(s)).expectComplete().verify();
server.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method testIssue292.
@Test
public void testIssue292() {
NettyContext server = HttpServer.create(options -> options.compression(10).port(0)).newHandler((req, res) -> res.sendHeaders().sendString(Flux.just("test", "test", "test", "test"))).block(Duration.ofSeconds(30));
Mono<String> response = HttpClient.create(options -> options.port(server.address().getPort()).compression(true)).get("/").flatMap(res -> res.receive().aggregate().asString());
StepVerifier.create(response).expectNextMatches(s -> "testtesttesttest".equals(s)).expectComplete().verify();
response = HttpClient.create(options -> options.port(server.address().getPort()).compression(true)).get("/").flatMap(res -> res.receive().aggregate().asString());
StepVerifier.create(response).expectNextMatches(s -> "testtesttesttest".equals(s)).expectComplete().verify();
server.dispose();
}
Aggregations