@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new DefaultCookie(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge(httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.response.addCookie(cookie); } } }
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new DefaultCookie(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge(httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.response.addCookie(cookie); } } }
.port(0) .cookieCodec(ServerCookieEncoder.LAX, ServerCookieDecoder.LAX) .handle((req, res) -> res.addCookie(new DefaultCookie("cookie1", "test_value")) .sendString(Mono.just("test"))) .wiretap(true)
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new DefaultCookie(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge(httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.response.addCookie(cookie); } } }
@Test public void clientWithoutCookieGetsANewOneFromServer() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.get("/test", (req, resp) -> resp.addCookie(new DefaultCookie("cookie1", "test_value")) .send(req.receive() .log("server received")))) .wiretap(true) .bindNow(); Mono<Map<CharSequence, Set<Cookie>>> cookieResponse = HttpClient.create() .port(server.port()) .wiretap(true) .get() .uri("/test") .responseSingle((res, buf) -> Mono.just(res.cookies())) .doOnSuccess(System.out::println) .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(cookieResponse) .expectNextMatches(l -> { Set<Cookie> cookies = l.get("cookie1"); return cookies.stream().anyMatch(e -> e.value().equals("test_value")); }) .expectComplete() .verify(Duration.ofSeconds(30)); server.disposeNow(); }
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new DefaultCookie(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge(httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.response.addCookie(cookie); } } }