HeaderFilters { public static HeaderFilter removeHeaders( final String... names) { return headers -> headers.delete(names); } private  HeaderFilters(); @API(status = MAINTAINED) static HeaderFilter defaultValue(); @API(status = MAINTAINED) static HeaderFilter authorization(); static HeaderFilter replaceHeaders(
            final String name,
            final String replacement); static HeaderFilter replaceHeaders(
            final Collection<String> names,
            final String replacement); static HeaderFilter replaceCookies(
            final Predicate<String> predicate, final String replacement); static HeaderFilter replaceHeaders(
            final Predicate<String> keyPredicate,
            final String replacement); static HeaderFilter replaceHeaders(
            final BiPredicate<String, String> predicate,
            final String replacement); static HeaderFilter eachHeader(
            final BinaryOperator<String> operator); static HeaderFilter removeHeaders(
            final String... names); static HeaderFilter removeHeaders(
            final Predicate<String> predicate); static HeaderFilter removeHeaders(
            final BiPredicate<String, String> predicate);  }
@Test void shouldRemoveHeaderByName() { final HeaderFilter unit = removeHeaders("name"); final HttpHeaders filtered = unit.filter( HttpHeaders.of("name", "Alice", "Bob")); assertThat(filtered, not(hasKey("name"))); }
@Test void shouldRemoveHeaderByNamePredicate() { final HeaderFilter unit = removeHeaders("name"::equals); final HttpHeaders filtered = unit.filter( HttpHeaders.empty() .update("name", "Alice", "Bob") .update("age", "18")); assertThat(filtered, not(hasKey("name"))); assertThat(filtered, hasEntry("age", singletonList("18"))); }
@Test void shouldRemoveHeaderByNameAndValue() { final HeaderFilter unit = removeHeaders((name, value) -> "name".equals(name) && "Alice".equals(value)); final HttpHeaders filtered = unit.filter( HttpHeaders.of("name", "Alice", "Bob")); assertThat(filtered, not(hasEntry("name", singletonList("Alice")))); assertThat(filtered, hasEntry("name", singletonList("Bob"))); }
@Test void shouldRemoveHeaderByValue() { final HeaderFilter unit = removeHeaders( (name, value) -> "Alice".equals(value)); final HttpHeaders filtered = unit.filter( HttpHeaders.of("name", "Alice", "Bob")); assertThat(filtered, not(hasEntry("name", singletonList("Alice")))); assertThat(filtered, hasEntry("name", singletonList("Bob"))); }
@Test void removesWholeHeader() { final HeaderFilter unit = removeHeaders((name, value) -> "Set-Cookie".equals(name)); final HttpHeaders actual = unit.filter( HttpHeaders.of("Set-Cookie", "version=1", "user=me")); assertEquals(actual, HttpHeaders.empty()); }
@Test void applyLeavesAlreadyEmptyListUntouched() { final HeaderFilter unit = removeHeaders((name, value) -> "Set-Cookie".equals(name)); final HttpHeaders headers = HttpHeaders.of("Set-Cookie"); final HttpHeaders actual = unit.filter(headers); assertSame(actual, headers); assertFalse(actual.isEmpty()); }
@Test void applyLeavesHeadersUntouched() { final HeaderFilter unit = removeHeaders((name, value) -> "Set-Cookie".equals(name) && "version=2".equals(value)); final HttpHeaders headers = HttpHeaders.of( "Set-Cookie", "version=1", "user=me"); final HttpHeaders actual = unit.filter(headers); assertSame(headers, actual); }