@Test public void testSendFile() throws Exception { String content = TestUtils.randomUnicodeString(10000); sendFile("test-send-file.html", content, false, handler -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, handler)); }
@Test public void testSendFileWithHandler() throws Exception { String content = TestUtils.randomUnicodeString(10000); sendFile("test-send-file.html", content, true, handler -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, handler)); }
@Test public void testSendFileWithConnectionCloseHeader() throws Exception { String content = TestUtils.randomUnicodeString(1024 * 1024 * 2); sendFile("test-send-file.html", content, false, handler -> client .get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, handler) .putHeader(HttpHeaders.CONNECTION, "close")); }
@Test public void testSetChunkedToFalse() throws Exception { server.requestHandler(req -> req.response().setChunked(false).end()); startServer(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", resp -> { testComplete(); }).setChunked(false).end(); await(); }
@Test public void testFallbackOnHttp1() throws Exception { server.close(); server = vertx.createHttpServer(serverOptions.setUseAlpn(false)); server.requestHandler(req -> { assertEquals(HttpVersion.HTTP_1_1, req.version()); req.response().end(); }); startServer(); client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { testComplete(); }).exceptionHandler(this::fail).end(); await(); }
@Test public void testClientMakeRequestHttp2WithSSLWithoutAlpn() throws Exception { client.close(); client = vertx.createHttpClient(createBaseClientOptions().setUseAlpn(false)); try { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI); fail(); } catch (IllegalArgumentException ignore) { // Expected } }
@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 testServerResponseWriteBufferFromOtherThread() throws Exception { server.requestHandler(req -> { runAsync(() -> { req.response().write("hello ").end("world"); }); }).listen(onSuccess(v -> { client.get(8080, "localhost", "/somepath", onSuccess(resp -> { assertEquals(200, resp.statusCode()); resp.bodyHandler(buff -> { assertEquals(Buffer.buffer("hello world"), buff); testComplete(); }); })).exceptionHandler(this::fail).end(); })); await(); }
@Test public void testConnectionFailed() throws Exception { client.get(4044, DEFAULT_HTTPS_HOST, "/somepath", onFailure(err -> { Context ctx = Vertx.currentContext(); assertOnIOContext(ctx); assertTrue(err instanceof ConnectException); testComplete(); })).end(); await(); }
private void handshake(Handler<NetSocket> handler) { HttpClientRequest request = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(resp -> { assertEquals(101, resp.statusCode()); handler.handle(resp.netSocket()); }) ); request .putHeader("Upgrade", "websocket") .putHeader("Connection", "Upgrade") .putHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==") .putHeader("Sec-WebSocket-Protocol", "chat") .putHeader("Sec-WebSocket-Version", "13") .putHeader("Origin", "http://example.com"); request.end(); }
@Test public void testServerDoesNotSupportAlpn() throws Exception { waitFor(2); server.close(); server = vertx.createHttpServer(createBaseServerOptions().setUseAlpn(false)); server.requestHandler(req -> { assertEquals(HttpVersion.HTTP_1_1, req.version()); req.response().end(); complete(); }); startServer(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { assertEquals(HttpVersion.HTTP_1_1, resp.version()); complete(); })).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 public void testServerResponseResetFromOtherThread() throws Exception { waitFor(2); server.requestHandler(req -> { runAsync(() -> { req.response().reset(0); }); }).listen(onSuccess(v -> { client.get(8080, "localhost", "/somepath", onFailure(err -> { assertTrue(err instanceof StreamResetException); complete(); })).exceptionHandler(err -> { assertTrue(err instanceof StreamResetException); complete(); }).sendHead(); })); 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")); }
@Test public void testRequestEntityTooLarge() { String path = "/some/path"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> fail()); server.listen(onSuccess(ar -> { client.get(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTPS_HOST, path, onSuccess(resp -> { assertEquals(413, resp.statusCode()); resp.request().connection().closeHandler(v -> { testComplete(); }); })).putHeader("Upgrade", "Websocket") .putHeader("Connection", "Upgrade") .end(TestUtils.randomBuffer(8192 + 1)); })); await(); }
@Test public void testResetPendingPushPromise() throws Exception { server.requestHandler(req -> { req.response().push(HttpMethod.GET, "/wibble", ar -> { assertFalse(ar.succeeded()); testComplete(); }); }); startServer(); client.close(); client = vertx.createHttpClient(clientOptions.setInitialSettings(new io.vertx.core.http.Http2Settings().setMaxConcurrentStreams(0L))); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onFailure(resp -> {})); req.pushHandler(pushedReq -> { pushedReq.reset(Http2Error.CANCEL.code()); }); req.end(); await(); }
@Test public void testHttpProxyRequest() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); testHttpProxyRequest2(handler -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", handler)); }
@Test public void testClientDoesNotSupportAlpn() throws Exception { waitFor(2); server.requestHandler(req -> { assertEquals(HttpVersion.HTTP_1_1, req.version()); req.response().end(); complete(); }); startServer(); client.close(); client = vertx.createHttpClient(createBaseClientOptions().setProtocolVersion(HttpVersion.HTTP_1_1).setUseAlpn(false)); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { assertEquals(HttpVersion.HTTP_1_1, resp.version()); complete(); })).exceptionHandler(this::fail).end(); await(); }
@Test public void testPerPeerPoolingWithProxy() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false).setProxyOptions(new ProxyOptions() .setType(ProxyType.HTTP) .setHost(DEFAULT_HTTP_HOST) .setPort(DEFAULT_HTTP_PORT))); testPerXXXPooling((i, handler) -> client.get(80, "host" + i, "/somepath", handler), HttpServerRequest::host); }
@Test public void testHttpProxyRequestOverrideClientSsl() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setSsl(true).setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); testHttpProxyRequest2(handler -> client.get(new RequestOptions().setSsl(false).setHost("localhost").setPort(8080), handler)); }