use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class Http1xTLSTest method testRedirectFromSSL.
@Test
public void testRedirectFromSSL() throws Exception {
HttpServer redirectServer = vertx.createHttpServer(new HttpServerOptions().setSsl(true).setKeyStoreOptions(Cert.SERVER_JKS.get()).setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
req.response().setStatusCode(307).putHeader("location", "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI).end();
});
startServer(redirectServer);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.NONE, Trust.NONE).clientSSL(true).serverSSL(false).requestOptions(options).followRedirects(true).pass();
}
use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class Http1xTLSTest method testRedirectToSSL.
// Redirect tests
@Test
public void testRedirectToSSL() throws Exception {
HttpServer redirectServer = vertx.createHttpServer(new HttpServerOptions().setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
req.response().setStatusCode(307).putHeader("location", "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI).end();
});
startServer(redirectServer);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(DEFAULT_HTTP_PORT);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(true).requestOptions(options).followRedirects(true).pass();
}
use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class HostnameResolutionTest method testHttp.
@Test
public void testHttp() throws Exception {
HttpClient client = vertx.createHttpClient();
HttpServer server = vertx.createHttpServer().requestHandler(req -> {
req.response().end("foo");
});
try {
CountDownLatch listenLatch = new CountDownLatch(1);
server.listen(8080, "vertx.io", onSuccess(s -> {
listenLatch.countDown();
}));
awaitLatch(listenLatch);
client.getNow(8080, "vertx.io", "/somepath", resp -> {
Buffer buffer = Buffer.buffer();
resp.handler(buffer::appendBuffer);
resp.endHandler(v -> {
assertEquals(Buffer.buffer("foo"), buffer);
testComplete();
});
});
await();
} finally {
client.close();
server.close();
}
}
use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class HttpMetricsTest method testHttpClientLifecycle.
private void testHttpClientLifecycle(HttpVersion protocol) throws Exception {
HttpServer server = vertx.createHttpServer();
CountDownLatch requestBeginLatch = new CountDownLatch(1);
CountDownLatch requestBodyLatch = new CountDownLatch(1);
CountDownLatch requestEndLatch = new CountDownLatch(1);
CompletableFuture<Void> beginResponse = new CompletableFuture<>();
CompletableFuture<Void> endResponse = new CompletableFuture<>();
server.requestHandler(req -> {
assertEquals(protocol, req.version());
requestBeginLatch.countDown();
req.handler(buff -> {
requestBodyLatch.countDown();
});
req.endHandler(v -> {
requestEndLatch.countDown();
});
Context ctx = vertx.getOrCreateContext();
beginResponse.thenAccept(v1 -> {
ctx.runOnContext(v2 -> {
req.response().setChunked(true).write(TestUtils.randomAlphaString(1024));
});
});
endResponse.thenAccept(v1 -> {
ctx.runOnContext(v2 -> {
req.response().end();
});
});
});
CountDownLatch listenLatch = new CountDownLatch(1);
server.listen(8080, "localhost", onSuccess(s -> {
listenLatch.countDown();
}));
awaitLatch(listenLatch);
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(protocol));
FakeHttpClientMetrics clientMetrics = FakeMetricsBase.getMetrics(client);
CountDownLatch responseBeginLatch = new CountDownLatch(1);
CountDownLatch responseEndLatch = new CountDownLatch(1);
HttpClientRequest req = client.post(8080, "localhost", "/somepath", resp -> {
responseBeginLatch.countDown();
resp.endHandler(v -> {
responseEndLatch.countDown();
});
}).setChunked(true);
req.sendHead();
awaitLatch(requestBeginLatch);
HttpClientMetric reqMetric = clientMetrics.getMetric(req);
assertEquals(0, reqMetric.requestEnded.get());
assertEquals(0, reqMetric.responseBegin.get());
req.write(TestUtils.randomAlphaString(1024));
awaitLatch(requestBodyLatch);
assertEquals(0, reqMetric.requestEnded.get());
assertEquals(0, reqMetric.responseBegin.get());
req.end();
awaitLatch(requestEndLatch);
assertEquals(1, reqMetric.requestEnded.get());
assertEquals(0, reqMetric.responseBegin.get());
beginResponse.complete(null);
awaitLatch(responseBeginLatch);
assertEquals(1, reqMetric.requestEnded.get());
assertEquals(1, reqMetric.responseBegin.get());
endResponse.complete(null);
awaitLatch(responseEndLatch);
assertNull(clientMetrics.getMetric(req));
assertEquals(1, reqMetric.requestEnded.get());
assertEquals(1, reqMetric.responseBegin.get());
}
use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class SimpleServer method start.
@Override
public void start(Future<Void> startFuture) throws Exception {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestHandler(req -> req.response().end());
server.listen(res -> {
if (res.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(res.cause());
}
});
}
Aggregations