private void testRequest(HttpMethod method) throws Exception { testRequest(client -> { switch (method) { case GET: return client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath"); case HEAD: return client.head(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath"); case DELETE: return client.delete(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath"); default: fail("Invalid HTTP method"); return null; } }, req -> assertEquals(method, req.method())); }
@Test public void testRequestPumpErrorNotYetConnected() throws Exception { HttpRequest<Buffer> post = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath"); server.requestHandler(req -> fail()); Throwable cause = new Throwable(); startServer();
complete(); } else { fail(new Exception("Unexpected failure", err));
break; default: fail("Invalid HTTP method");
@Test public void testHttpProxyFtpRequest() throws Exception { startProxy(null, ProxyType.HTTP); proxy.setForceUri("http://" + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT); server.requestHandler(req -> req.response().setStatusCode(200).end()); startServer(); WebClientOptions options = new WebClientOptions(); options.setProxyOptions(new ProxyOptions().setPort(proxy.getPort())); WebClient client = WebClient.create(vertx, options); client .getAbs("ftp://ftp.gnu.org/gnu/") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); assertEquals(200, response.statusCode()); assertEquals("ftp://ftp.gnu.org/gnu/", proxy.getLastUri()); testComplete(); } else { fail(ar.cause()); } }); await(); }
server.requestHandler(req -> { if (!req.headers().contains("foo", "bar", true)) { fail("Missing expected header"); return;