CookiesMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { @Override public HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> next) { cookiesRequest(request); HttpResponse response = castToHttpResponse(next.next(request)); if (response != null) { cookiesResponse(response); } return response; }  @Override HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> next);  }
@Test void parse() { MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, (Endpoint<HttpRequest, HttpResponse>) req -> { assertThat(some(req.getCookies().get("A"), Cookie::getValue).orElseThrow(AssertionError::new)) .isEqualTo("あいう"); assertThat(some(req.getCookies().get("B"), Cookie::getValue).orElseThrow(AssertionError::new)) .isEqualTo("1"); return builder(HttpResponse.of("hello")) .set(HttpResponse::setHeaders, Headers.of("Content-Type", "text/html")) .build(); }); request.getHeaders().put("Cookie", "A=%E3%81%82%E3%81%84%E3%81%86; B=1"); middleware.handle(request, chain); }