use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method testIssue186.
@Test
public void testIssue186() {
NettyContext server = HttpServer.create(0).newHandler((req, res) -> res.status(200).send()).block(Duration.ofSeconds(300));
HttpClient client = HttpClient.create(ops -> ops.connectAddress(() -> server.address()).poolResources(PoolResources.fixed("test", 1)));
try {
doTestIssue186(client);
doTestIssue186(client);
} finally {
server.dispose();
}
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method testContentLengthHeadRequest.
@Test
public void testContentLengthHeadRequest() {
NettyContext server = HttpServer.create(ops -> ops.host("localhost")).newRouter(r -> r.route(req -> req.uri().startsWith("/1"), (req, res) -> res.sendString(Mono.just("OK"))).route(req -> req.uri().startsWith("/2"), (req, res) -> res.chunkedTransfer(false).sendString(Mono.just("OK"))).route(req -> req.uri().startsWith("/3"), (req, res) -> {
res.responseHeaders().set("Content-Length", 2);
return res.sendString(Mono.just("OK"));
}).route(req -> req.uri().startsWith("/4"), (req, res) -> res.sendHeaders()).route(req -> req.uri().startsWith("/5"), (req, res) -> res.chunkedTransfer(false).sendHeaders()).route(req -> req.uri().startsWith("/6"), (req, res) -> {
res.responseHeaders().set("Content-Length", 2);
return res.sendHeaders();
}).route(req -> req.uri().startsWith("/7"), (req, res) -> res.send()).route(req -> req.uri().startsWith("/8"), (req, res) -> res.chunkedTransfer(false).send()).route(req -> req.uri().startsWith("/9"), (req, res) -> {
res.responseHeaders().set("Content-Length", 2);
return res.send();
})).block(Duration.ofSeconds(30));
doTestContentLengthHeadRequest("/1", server.address(), HttpMethod.GET, true, false);
doTestContentLengthHeadRequest("/1", server.address(), HttpMethod.HEAD, true, false);
doTestContentLengthHeadRequest("/2", server.address(), HttpMethod.GET, false, true);
doTestContentLengthHeadRequest("/2", server.address(), HttpMethod.HEAD, false, true);
doTestContentLengthHeadRequest("/3", server.address(), HttpMethod.GET, false, false);
doTestContentLengthHeadRequest("/3", server.address(), HttpMethod.HEAD, false, false);
doTestContentLengthHeadRequest("/4", server.address(), HttpMethod.HEAD, true, false);
doTestContentLengthHeadRequest("/5", server.address(), HttpMethod.HEAD, false, true);
doTestContentLengthHeadRequest("/6", server.address(), HttpMethod.HEAD, false, false);
doTestContentLengthHeadRequest("/7", server.address(), HttpMethod.HEAD, true, false);
doTestContentLengthHeadRequest("/8", server.address(), HttpMethod.HEAD, false, true);
doTestContentLengthHeadRequest("/9", server.address(), HttpMethod.HEAD, false, false);
server.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method testRestart.
// from https://github.com/reactor/reactor-netty/issues/90
@Test
public void testRestart() {
// start a first server with a handler that answers HTTP 200 OK
NettyContext context = HttpServer.create(8080).newHandler((req, resp) -> resp.status(200).send().log()).block();
HttpClientResponse response = HttpClient.create(8080).get("/").block();
// checking the response status, OK
assertThat(response.status().code()).isEqualTo(200);
// dispose the Netty context and wait for the channel close
response.dispose();
context.dispose();
context.onClose().block();
// REQUIRED - bug pool does not detect/translate properly lifecycle
HttpResources.reset();
// create a totally new server instance, with a different handler that answers HTTP 201
context = HttpServer.create(8080).newHandler((req, resp) -> resp.status(201).send()).block();
response = HttpClient.create(8080).get("/").block();
// fails, response status is 200 and debugging shows the the previous handler is called
assertThat(response.status().code()).isEqualTo(201);
response.dispose();
context.dispose();
context.onClose().block();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method errorResponseAndReturn.
@Test
public void errorResponseAndReturn() throws Exception {
NettyContext c = HttpServer.create(0).newHandler((req, resp) -> Mono.error(new Exception("returnError"))).block();
HttpClientResponse res = HttpClient.create(c.address().getPort()).get("/return", r -> r.failOnServerError(false)).block();
assertThat(res.status().code()).isEqualTo(500);
res.dispose();
c.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method assertSendFile.
private void assertSendFile(Function<HttpServerResponse, NettyOutbound> fn) {
NettyContext context = HttpServer.create(opt -> opt.host("localhost")).newHandler((req, resp) -> fn.apply(resp)).block();
HttpClientResponse response = HttpClient.create(opt -> opt.connectAddress(() -> context.address())).get("/foo").block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String body = response.receive().aggregate().asString(StandardCharsets.UTF_8).block();
assertThat(body).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
Aggregations