req.setHost(host + addPort); } else { req = new HttpClientRequestImpl(this, useSSL, method, host, port, relativeURI, vertx);
@Test public void testHostHeaderOverridePossible() { server.requestHandler(req -> { assertEquals("localhost:4444", req.host()); req.response().end(); }); server.listen(onSuccess(s -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete()); req.setHost("localhost:4444"); req.end(); })); await(); }
@Test public void testOverrideAuthority() throws Exception { server.requestHandler(req -> { assertEquals("localhost:4444", req.host()); req.response().end(); }); startServer(); client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { testComplete(); }) .setHost("localhost:4444") .exceptionHandler(this::fail) .end(); await(); }
@Test public void testPerPeerPooling() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false)); testPerXXXPooling((i, handler) -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", handler).setHost("host" + i + ":8080"), HttpServerRequest::host); }
@Test // Client provides SNI and server responds with a matching certificate for the indicated server name public void testSNIWithHostHeader() throws Exception { X509Certificate cert = testTLS(Cert.NONE, Trust.SNI_JKS_HOST2, Cert.SNI_JKS, Trust.NONE) .serverSni() .requestProvider((client, handler) -> client.post(4043, "localhost", "/somepath", handler).setHost("host2.com:4043")) .pass() .clientPeerCert(); assertEquals("host2.com", TestUtils.cnOf(cert)); }
@Test public void testFollowRedirectHost() throws Exception { String scheme = createBaseClientOptions().isSsl() ? "https" : "http"; waitFor(2); HttpServerOptions options = createBaseServerOptions(); int port = options.getPort() + 1; options.setPort(port); AtomicInteger redirects = new AtomicInteger(); server.requestHandler(req -> { redirects.incrementAndGet(); req.response().setStatusCode(301).putHeader(HttpHeaders.LOCATION, scheme + "://localhost:" + port + "/whatever").end(); }); startServer(); HttpServer server2 = vertx.createHttpServer(options); server2.requestHandler(req -> { assertEquals(1, redirects.get()); assertEquals(scheme + "://localhost:" + port + "/whatever", req.absoluteURI()); req.response().end(); complete(); }); startServer(server2); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp -> { assertEquals(scheme + "://localhost:" + port + "/whatever", resp.request().absoluteURI()); complete(); })).setFollowRedirects(true).setHost("localhost:" + options.getPort()).end(); await(); }
HttpClientRequest req = client.getAbs(scheme + "://localhost:" + port + "/custom"); req.putHeader("foo", "foo_another"); req.setHost("localhost:" + port); fut.complete(req); }); assertEquals(scheme + "://localhost:" + port + "/custom", resp.request().absoluteURI()); complete(); })).setFollowRedirects(true).putHeader("foo", "foo_value").setHost("localhost:" + options.getPort()).end(); await();
@Test public void testPerHostPooling() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false)); testPerXXXPooling((i, handler) -> client.get(DEFAULT_HTTP_PORT, "host" + i, "/somepath", handler).setHost("host:8080") .putHeader("key", "host" + i), req -> req.getHeader("key")); }
req.setHost(host + addPort); } else { req = new HttpClientRequestImpl(this, useSSL, method, host, port, relativeURI, vertx);
@Test public void testHostHeaderOverridePossible() { server.requestHandler(req -> { assertEquals("localhost:4444", req.host()); req.response().end(); }); server.listen(onSuccess(s -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete()); req.setHost("localhost:4444"); req.end(); })); await(); }
@Test public void testOverrideAuthority() throws Exception { server.requestHandler(req -> { assertEquals("localhost:4444", req.host()); req.response().end(); }); startServer(); client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { testComplete(); }) .setHost("localhost:4444") .exceptionHandler(this::fail) .end(); await(); }
@Test public void testVHost() throws Exception { router.route().handler(VirtualHostHandler.create("*.com", ctx -> ctx.response().end())); router.route().handler(ctx -> ctx.fail(500)); testRequest(HttpMethod.GET, "/", req -> req.setHost("www.mysite.com"), 200, "OK", null); }
@Test public void testVHostShouldFail() throws Exception { router.route().handler(VirtualHostHandler.create("*.com", ctx -> ctx.response().end())); router.route().handler(ctx -> ctx.fail(500)); testRequest(HttpMethod.GET, "/", req -> req.setHost("www.mysite.net"), 500, "Internal Server Error", null); } }
@Test public void testVHost() throws Exception { router.route().handler(VirtualHostHandler.create("*.com", ctx -> ctx.response().end())); router.route().handler(ctx -> ctx.fail(500)); testRequest(HttpMethod.GET, "/", req -> req.setHost("www.mysite.com"), 200, "OK", null); }
@Test public void testVHostShouldFail() throws Exception { router.route().handler(VirtualHostHandler.create("*.com", ctx -> ctx.response().end())); router.route().handler(ctx -> ctx.fail(500)); testRequest(HttpMethod.GET, "/", req -> req.setHost("www.mysite.net"), 500, "Internal Server Error", null); } }
@Test public void testFollowRedirectHost() throws Exception { String scheme = createBaseClientOptions().isSsl() ? "https" : "http"; waitFor(2); HttpServerOptions options = createBaseServerOptions(); int port = options.getPort() + 1; options.setPort(port); AtomicInteger redirects = new AtomicInteger(); server.requestHandler(req -> { redirects.incrementAndGet(); req.response().setStatusCode(301).putHeader(HttpHeaders.LOCATION, scheme + "://localhost:" + port + "/whatever").end(); }); startServer(); HttpServer server2 = vertx.createHttpServer(options); server2.requestHandler(req -> { assertEquals(1, redirects.get()); assertEquals(scheme + "://localhost:" + port + "/whatever", req.absoluteURI()); req.response().end(); complete(); }); startServer(server2); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> { assertEquals(scheme + "://localhost:" + port + "/whatever", resp.request().absoluteURI()); complete(); }).setFollowRedirects(true).setHost("localhost:" + options.getPort()).end(); await(); }
@Test // Client provides SNI and server responds with a matching certificate for the indicated server name public void testSNIWithHostHeader() throws Exception { X509Certificate cert = testTLS(Cert.NONE, Trust.SNI_JKS_HOST2, Cert.SNI_JKS, Trust.NONE) .serverSni() .requestProvider(client -> client.post(4043, "localhost", "/somepath").setHost("host2.com:4043")) .pass() .clientPeerCert(); assertEquals("host2.com", TestUtils.cnOf(cert)); }
@Test public void testPerPeerPooling() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false)); testPerXXXPooling(i -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath").setHost("host" + i + ":8080"), HttpServerRequest::host); }
HttpClientRequest req = client.getAbs(scheme + "://localhost:" + port + "/custom"); req.putHeader("foo", "foo_another"); req.setHost("localhost:" + port); fut.complete(req); }); assertEquals(scheme + "://localhost:" + port + "/custom", resp.request().absoluteURI()); complete(); }).setFollowRedirects(true).putHeader("foo", "foo_value").setHost("localhost:" + options.getPort()).end(); await();
@Test public void testPerHostPooling() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false)); testPerXXXPooling(i -> client.get(DEFAULT_HTTP_PORT, "host" + i, "/somepath").setHost("host:8080") .putHeader("key", "host" + i), req -> req.getHeader("key")); }