diff -r 8588095e95b0 -r 352e845ae744 src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ImmutableHeaders.java --- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ImmutableHeaders.java Wed Jan 31 15:52:35 2018 +0000 +++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ImmutableHeaders.java Wed Jan 31 16:18:41 2018 +0000 @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.function.BiPredicate; import java.util.function.Predicate; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableList; @@ -57,14 +58,21 @@ Predicate keyAllowed) { requireNonNull(src, "src"); requireNonNull(keyAllowed, "keyAllowed"); - return new ImmutableHeaders(src, keyAllowed); + return new ImmutableHeaders(src, headerAllowed(keyAllowed)); + } + + public static ImmutableHeaders of(Map> src, + BiPredicate> headerAllowed) { + requireNonNull(src, "src"); + requireNonNull(headerAllowed, "headerAllowed"); + return new ImmutableHeaders(src, headerAllowed); } private ImmutableHeaders(Map> src, - Predicate keyAllowed) { + BiPredicate> headerAllowed) { Map> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); src.entrySet().stream() - .filter(e -> keyAllowed.test(e.getKey())) + .filter(e -> headerAllowed.test(e.getKey(), e.getValue())) .forEach(e -> { List values = new ArrayList<>(e.getValue()); @@ -74,6 +82,10 @@ this.map = unmodifiableMap(m); } + private static BiPredicate> headerAllowed(Predicate keyAllowed) { + return (n,v) -> keyAllowed.test(n); + } + @Override public Map> map() { return map;