use of reactor.ipc.netty.http.server.HttpServer in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method serverCompressionEnabledSmallResponse.
@Test
public void serverCompressionEnabledSmallResponse() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression(25));
NettyContext nettyContext = server.newHandler((in, out) -> out.header("content-length", "5").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("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 serverCompressionPredicateTrue.
@Test
public void serverCompressionPredicateTrue() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression((req, res) -> 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.http.server.HttpServer in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method serverCompressionDisabled.
@Test
public void serverCompressionDisabled() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression(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();
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.http.server.HttpServer in project reactor-netty by reactor.
the class HttpClientTest method closePool.
@Test
public void closePool() {
PoolResources pr = PoolResources.fixed("wstest", 1);
NettyContext httpServer = HttpServer.create(0).newHandler((in, out) -> out.options(opt -> opt.flushOnEach()).sendString(Mono.just("test").delayElement(Duration.ofMillis(100)).repeat())).block(Duration.ofSeconds(30));
Flux<String> ws = HttpClient.create(opts -> opts.port(httpServer.address().getPort()).poolResources(pr)).get("/").flatMapMany(in -> in.receive().asString());
StepVerifier.create(Flux.range(1, 10).concatMap(i -> ws.take(2).log())).expectNextSequence(Flux.range(1, 20).map(v -> "test").toIterable()).expectComplete().verify();
httpServer.dispose();
pr.dispose();
}
use of reactor.ipc.netty.http.server.HttpServer in project reactor-netty by reactor.
the class ProxyClientIssue method startProxyServer.
@Test
@Ignore
public void startProxyServer() throws Exception {
HttpServer server = HttpServer.create(options -> options.host("0.0.0.0").port(PROXY_PORT));
server.startRouterAndAwait(routes -> routes.get("/0/**", this::proxy));
}
Aggregations