diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java index 7bf25d2cfd..0d87250adb 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,11 +91,9 @@ class Netty5HeadersAdapter implements MultiValueMap { @Override public Map toSingleValueMap() { Map singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size()); - this.headers.forEach(entry -> { - if (!singleValueMap.containsKey(entry.getKey())) { - singleValueMap.put(entry.getKey().toString(), entry.getValue().toString()); - } - }); + this.headers.forEach(entry -> + singleValueMap.putIfAbsent(entry.getKey().toString(), entry.getValue().toString()) + ); return singleValueMap; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java index 35714334a1..e6d3b26f60 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,11 +89,9 @@ final class Netty5HeadersAdapter implements MultiValueMap { @Override public Map toSingleValueMap() { Map singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size()); - this.headers.forEach(entry -> { - if (!singleValueMap.containsKey(entry.getKey())) { - singleValueMap.put(entry.getKey().toString(), entry.getValue().toString()); - } - }); + this.headers.forEach(entry -> + singleValueMap.putIfAbsent(entry.getKey().toString(), entry.getValue().toString()) + ); return singleValueMap; }