use of reactor.ipc.netty.http.server.HttpServer in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method serverCompressionPredicateFalse.
@Test
public void serverCompressionPredicateFalse() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression((req, res) -> false));
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();
// check the server didn't send the gzip header, only transfer-encoding
HttpHeaders headers = resp.responseHeaders();
assertThat(headers.get("transFER-encoding")).isEqualTo("chunked");
assertThat(headers.get("conTENT-encoding")).isNull();
// check the server sent plain text
String reply = resp.receive().asString().blockFirst();
Assert.assertEquals("reply", reply);
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
use of reactor.ipc.netty.http.server.HttpServer in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method compressionActivatedOnClientAddsHeader.
@Test
public void compressionActivatedOnClientAddsHeader() {
AtomicReference<String> zip = new AtomicReference<>("fail");
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));
HttpClient client = HttpClient.create(opt -> opt.compression(true).connectAddress(() -> address(nettyContext)));
HttpClientResponse resp = client.get("/test", req -> {
zip.set(req.requestHeaders().get("accept-encoding"));
return req;
}).block();
assertThat(zip.get()).isEqualTo("gzip");
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
use of reactor.ipc.netty.http.server.HttpServer in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method compressionServerEnabledClientDisabledIsNone.
@Test
public void compressionServerEnabledClientDisabledIsNone() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression(true));
String serverReply = "reply";
NettyContext nettyContext = server.newHandler((in, out) -> out.sendString(Mono.just(serverReply))).block(Duration.ofMillis(10_000));
HttpClient client = HttpClient.create(o -> o.compression(false).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(serverReply);
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
Aggregations