Cookie c = new DefaultCookie("test", "localhost"); c.setPath("/"); client.cookieStore().remove(c); r.send(ar -> { async.complete(); validate(context, client.cookieStore().get(false, "localhost", "/"), new String[] { "test" }, new String[] { "toast" }); }); check.accept(client.delete("/")); check.accept(client.delete("localhost", "/")); check.accept(client.delete(PORT, "localhost", "/")); check.accept(client.deleteAbs("http://localhost/")); check.accept(client.get("/")); check.accept(client.get("localhost", "/")); check.accept(client.get(PORT, "localhost", "/")); check.accept(client.getAbs("http://localhost/")); check.accept(client.head("/")); check.accept(client.head("localhost", "/")); check.accept(client.head(PORT, "localhost", "/")); check.accept(client.headAbs("http://localhost/")); check.accept(client.patch("/")); check.accept(client.patch("localhost", "/")); check.accept(client.patch(PORT, "localhost", "/")); check.accept(client.patchAbs("http://localhost/")); check.accept(client.post("/")); check.accept(client.post("localhost", "/")); check.accept(client.post(PORT, "localhost", "/")); check.accept(client.postAbs("http://localhost/"));
private WebClientSession buildClient(WebClient webClient, CookieStore cookieStore) { return WebClientSession.create(webClient, cookieStore); }
@Test public void testReadCookie(TestContext context) { Async async = context.async(); prepareServer(context, req -> { req.response().headers().add("set-cookie", ServerCookieEncoder.STRICT.encode(new DefaultCookie("test", "toast"))); }); client.get(PORT, "localhost", "/").send(ar -> { context.assertTrue(ar.succeeded()); validate(context, client.cookieStore().get(false, "localhost", "/"), new String[] { "test" }, new String[] { "toast" }); async.complete(); }); }
@Test public void testSessionHeaders(TestContext context) { String headerName = "x-client-header"; String headerVal = "MY-HEADER"; prepareServer(context, req -> { req.response().setChunked(true); if (headerVal.equals(req.getHeader(headerName))) { req.response().write("OK"); } else { req.response().write("ERR"); } }); Async async = context.async(); client.addHeader(headerName, headerVal); client.get("/").send(ar -> { context.assertTrue(ar.succeeded()); HttpResponse<Buffer> res = ar.result(); context.assertEquals(200, res.statusCode()); context.assertEquals("OK", res.bodyAsString()); async.complete(); }); }
@Override public void start() throws Exception { vertx.eventBus().consumer("test", m -> { client.get(host, uri).send(ar -> { testContext.assertTrue(ar.succeeded()); async.countDown(); }); }); } };
Iterable<Cookie> all = client.cookieStore().get(false, host, uri); for (Cookie c : all) { i++;
HttpRequest<Buffer> req = client.get(PORT, "localhost", "/index.html"); Iterable<Cookie> cookies = client.cookieStore().get(false, "localhost", "/");
HttpRequest<Buffer> req = client.get(PORT, "localhost", "/");
@Test public void testReadManyCookies(TestContext context) { Async async = context.async(); prepareServer(context, req -> { req.response().headers().add("set-cookie", ServerCookieEncoder.STRICT.encode(new DefaultCookie("test1", "toast1"))); req.response().headers().add("set-cookie", ServerCookieEncoder.STRICT.encode(new DefaultCookie("test2", "toast2"))); req.response().headers().add("set-cookie", ServerCookieEncoder.STRICT.encode(new DefaultCookie("test3", "toast3"))); }); client.get(PORT, "localhost", "/").send(ar -> { context.assertTrue(ar.succeeded()); validate(context, client.cookieStore().get(false, "localhost", "/"), new String[] { "test1" ,"test2", "test3" }, new String[] { "toast1", "toast2", "toast3" }); async.complete(); }); }
HttpRequest<Buffer> req = client.get(PORT, "localhost", "/") .putHeader(headerName, headerValue) .addQueryParam("c", "X");
HttpRequest<Buffer> req = client.get(PORT, "localhost", pathToCall);