diff --git a/java/src/org/openqa/selenium/remote/http/HttpMessage.java b/java/src/org/openqa/selenium/remote/http/HttpMessage.java index 8d388c8de0084..909d7ecf7bd97 100644 --- a/java/src/org/openqa/selenium/remote/http/HttpMessage.java +++ b/java/src/org/openqa/selenium/remote/http/HttpMessage.java @@ -29,11 +29,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Supplier; -import java.util.stream.Collectors; import org.openqa.selenium.internal.Require; abstract class HttpMessage> { @@ -92,11 +90,8 @@ public Iterable getHeaderNames() { * @return an iterable view of the values */ public Iterable getHeaders(String name) { - return headers.entrySet().stream() - .filter(e -> Objects.nonNull(e.getKey())) - .filter(e -> e.getKey().equalsIgnoreCase(name.toLowerCase())) - .flatMap((e) -> e.getValue().stream()) - .collect(Collectors.toList()); + return Collections.unmodifiableCollection( + headers.getOrDefault(name.toLowerCase(), Collections.emptyList())); } /** @@ -106,12 +101,8 @@ public Iterable getHeaders(String name) { * @return the value */ public String getHeader(String name) { - return headers.entrySet().stream() - .filter(e -> Objects.nonNull(e.getKey())) - .filter(e -> e.getKey().equalsIgnoreCase(name.toLowerCase())) - .flatMap((e) -> e.getValue().stream()) - .findFirst() - .orElse(null); + List values = headers.getOrDefault(name.toLowerCase(), Collections.emptyList()); + return !values.isEmpty() ? values.get(0) : null; } /** @@ -146,7 +137,7 @@ public M addHeader(String name, String value) { * @return self */ public M removeHeader(String name) { - headers.keySet().removeIf(header -> header.equalsIgnoreCase(name)); + headers.remove(name.toLowerCase()); return self(); }