From 829ac3fbefac37f936188edd43455d136a9734ca Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 24 Jul 2018 13:34:49 +0200 Subject: [PATCH] Prevent headers to be mutated This commit rework 1189ccc to prevent a mutate call on the original headers map. Closes gh-13871 --- .../boot/actuate/trace/http/HttpExchangeTracer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/http/HttpExchangeTracer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/http/HttpExchangeTracer.java index 2257149aa9..afbd23672b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/http/HttpExchangeTracer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/http/HttpExchangeTracer.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.springframework.http.HttpHeaders; @@ -101,9 +102,9 @@ public class HttpExchangeTracer { if (!this.includes.contains(include)) { return new LinkedHashMap<>(); } - Map> headers = headersSupplier.get(); - headers.keySet().removeIf((header) -> !headerPredicate.test(header)); - return headers; + return headersSupplier.get().entrySet().stream() + .filter((entry) -> headerPredicate.test(entry.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } private final class FilteredTraceableRequest implements TraceableRequest {