use of io.vertx.core.http.HttpClientRequest 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.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testSendPing.
@Test
public void testSendPing() throws Exception {
waitFor(2);
Buffer expected = TestUtils.randomBuffer(8);
Context ctx = vertx.getOrCreateContext();
server.close();
server.connectionHandler(conn -> {
conn.pingHandler(data -> {
assertEquals(expected, data);
complete();
});
});
server.requestHandler(req -> {
});
startServer(ctx);
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
});
req.connectionHandler(conn -> {
conn.ping(expected, ar -> {
assertTrue(ar.succeeded());
Buffer buff = ar.result();
assertEquals(expected, buff);
complete();
});
});
req.end();
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2Test method testClientStreamPausedWhenConnectionIsPaused.
@Test
public void testClientStreamPausedWhenConnectionIsPaused() throws Exception {
waitFor(2);
Buffer buffer = TestUtils.randomBuffer(512);
CompletableFuture<Void> resumeLatch = new CompletableFuture<>();
server.requestHandler(req -> {
switch(req.path()) {
case "/0":
{
req.pause();
resumeLatch.thenAccept(v -> {
req.resume();
});
req.endHandler(v -> {
req.response().end();
});
break;
}
case "/1":
{
req.bodyHandler(v -> {
assertEquals(v, buffer);
req.response().end();
});
break;
}
}
});
startServer();
HttpClientRequest req1 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/0", resp -> {
complete();
}).setChunked(true);
while (!req1.writeQueueFull()) {
req1.write(Buffer.buffer(TestUtils.randomAlphaString(512)));
Thread.sleep(1);
}
HttpClientRequest req2 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/1", resp -> {
complete();
}).setChunked(true);
assertFalse(req2.writeQueueFull());
req2.sendHead(v -> {
assertTrue(req2.writeQueueFull());
resumeLatch.complete(null);
});
resumeLatch.get(20, TimeUnit.SECONDS);
waitUntil(() -> !req2.writeQueueFull());
req1.end();
req2.end(buffer);
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2Test method testClientRequestWriteFromOtherThread.
@Test
public void testClientRequestWriteFromOtherThread() throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
server.requestHandler(req -> {
latch2.countDown();
req.endHandler(v -> {
req.response().end();
});
}).listen(onSuccess(v -> {
latch1.countDown();
}));
awaitLatch(latch1);
HttpClientRequest req = client.get(8080, "localhost", "/somepath", resp -> {
assertEquals(200, resp.statusCode());
testComplete();
}).setChunked(true).sendHead();
// The next write won't be buffered
awaitLatch(latch2);
req.write("hello ").end("world");
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class HttpTest method testFollowRedirectWithCustomHandler.
@Test
public void testFollowRedirectWithCustomHandler() throws Exception {
String scheme = createBaseClientOptions().isSsl() ? "https" : "http";
waitFor(2);
AtomicInteger redirections = new AtomicInteger();
server.requestHandler(req -> {
switch(redirections.getAndIncrement()) {
case 0:
req.response().setStatusCode(301).putHeader(HttpHeaders.LOCATION, "http://localhost:8080/whatever").end();
break;
case 1:
assertEquals(scheme + "://another_host/custom", req.absoluteURI());
req.response().end();
complete();
break;
}
});
startServer();
client.redirectHandler(resp -> {
Future<HttpClientRequest> fut = Future.future();
vertx.setTimer(25, id -> {
HttpClientRequest req = client.getAbs(scheme + "://localhost:8080/custom");
req.putHeader("foo", "foo_another");
req.setHost("another_host");
fut.complete(req);
});
return fut;
});
client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(scheme + "://another_host/custom", resp.request().absoluteURI());
complete();
}).setFollowRedirects(true).putHeader("foo", "foo_value").setHost("the_host").end();
await();
}
Aggregations