use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.
the class Http2ClientTest method testResetActivePushPromise.
@Test
public void testResetActivePushPromise() throws Exception {
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
HttpServerResponse response = ar.result();
response.exceptionHandler(err -> {
if (err instanceof StreamResetException) {
assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode());
testComplete();
}
});
response.setChunked(true).write("some_content");
});
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
});
req.pushHandler(pushedReq -> {
pushedReq.handler(pushedResp -> {
pushedResp.handler(buff -> {
pushedReq.reset(Http2Error.CANCEL.code());
});
});
});
req.end();
await();
}
use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.
the class Http2ClientTest method testResetPushPromiseNoHandler.
@Test
public void testResetPushPromiseNoHandler() throws Exception {
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
HttpServerResponse resp = ar.result();
resp.setChunked(true).write("content");
resp.exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode());
testComplete();
});
});
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
});
req.end();
await();
}
use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.
the class Http2ClientTest method testTrailers.
@Test
public void testTrailers() throws Exception {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.setChunked(true);
resp.write("some-content");
resp.putTrailer("Foo", "foo_value");
resp.putTrailer("bar", "bar_value");
resp.putTrailer("juu", (List<String>) Arrays.asList("juu_value_1", "juu_value_2"));
resp.end();
});
startServer();
client.getNow(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepeth", resp -> {
assertEquals(null, resp.getTrailer("foo"));
resp.exceptionHandler(this::fail);
resp.endHandler(v -> {
assertEquals("foo_value", resp.getTrailer("foo"));
assertEquals("foo_value", resp.getTrailer("Foo"));
assertEquals("bar_value", resp.getTrailer("bar"));
assertEquals(2, resp.trailers().getAll("juu").size());
assertEquals("juu_value_1", resp.trailers().getAll("juu").get(0));
assertEquals("juu_value_2", resp.trailers().getAll("juu").get(1));
testComplete();
});
});
await();
}
use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.
the class Http2ClientTest method testBodyEndHandler.
@Test
public void testBodyEndHandler() throws Exception {
// Large body so it will be fragmented in several HTTP2 data frames
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(128 * 1024));
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.end(expected);
});
startServer();
client.getNow(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
Context ctx = vertx.getOrCreateContext();
resp.exceptionHandler(this::fail);
resp.bodyHandler(body -> {
assertOnIOContext(ctx);
assertEquals(expected, body);
testComplete();
});
});
await();
}
use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.
the class Http2Test method testServerStreamPausedWhenConnectionIsPaused.
@Test
public void testServerStreamPausedWhenConnectionIsPaused() throws Exception {
CountDownLatch fullLatch = new CountDownLatch(1);
CompletableFuture<Void> resumeLatch = new CompletableFuture<>();
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
switch(req.path()) {
case "/0":
{
vertx.setPeriodic(1, timerID -> {
if (resp.writeQueueFull()) {
vertx.cancelTimer(timerID);
fullLatch.countDown();
} else {
resp.write(Buffer.buffer(TestUtils.randomAlphaString(512)));
}
});
break;
}
case "/1":
{
assertTrue(resp.writeQueueFull());
resp.drainHandler(v -> {
resp.end();
});
resumeLatch.complete(null);
break;
}
}
});
startServer();
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/0", resp -> {
resp.pause();
Context ctx = vertx.getOrCreateContext();
resumeLatch.thenAccept(v1 -> {
ctx.runOnContext(v2 -> {
resp.endHandler(v -> {
testComplete();
});
resp.resume();
});
});
});
awaitLatch(fullLatch);
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/1", resp -> {
resp.endHandler(v -> {
complete();
});
});
// Make sure it completes
resumeLatch.get(20, TimeUnit.SECONDS);
await();
}
Aggregations