CookieHeaderFilter implements HeaderFilter { @Override public HttpHeaders filter(final HttpHeaders headers) { for (final Entry<String, Processor> entry : processors.entrySet()) { final String name = entry.getKey(); final Processor processor = entry.getValue(); if (headers.containsKey(name)) { return replace(headers, name, processor); } } return headers; } CookieHeaderFilter(
            final Predicate<String> predicate, final String replacement); @Override HttpHeaders filter(final HttpHeaders headers); void processCookie(
            final Matcher matcher, final StringBuffer result); void processSetCookie(
            final Matcher matcher, final StringBuffer result);  }
@Test void parsesSetCookieHeader() { final HeaderFilter unit = replaceCookies("sessionToken"::equals, "XXX"); final HttpHeaders before = HttpHeaders.of( "Set-Cookie", "theme=light", "sessionToken=abc123; Path=/; Expires=Wed, 09 Jun 2021 10:18:14 GMT"); final HttpHeaders after = unit.filter(before); assertThat(after, hasEntry("Set-Cookie", asList( "theme=light", "sessionToken=XXX; Path=/; Expires=Wed, 09 Jun 2021 10:18:14 GMT" ))); }
@Test void ignoresEmptySetCookieHeader() { final HeaderFilter unit = replaceCookies("sessionToken"::equals, "XXX"); final HttpHeaders before = HttpHeaders.of("Set-Cookie", ""); final HttpHeaders after = unit.filter(before); assertThat(after, hasEntry("Set-Cookie", singletonList(""))); }
@Test void ignoresNoCookieHeaders() { final HeaderFilter unit = replaceCookies("sessionToken"::equals, "XXX"); final HttpHeaders after = unit.filter(HttpHeaders.empty()); assertThat(after, is(emptyMap())); }