From e66095b1a27d0b65ecf845585986b3beefc35a02 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 25 Nov 2021 22:03:11 +0100 Subject: [PATCH] Polish Closes gh-27466 --- .../web/filter/ForwardedHeaderFilter.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index 9d6bb2eed6..abb2b469b0 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -170,21 +170,18 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { public ForwardedHeaderRemovingRequest(HttpServletRequest request) { super(request); - this.headerNames = headerNames(request); } private static Set headerNames(HttpServletRequest request) { - final var headerNames = Collections.newSetFromMap(new LinkedCaseInsensitiveMap<>(Locale.ENGLISH)); - final var names = request.getHeaderNames(); - + Set headerNames = Collections.newSetFromMap(new LinkedCaseInsensitiveMap<>(Locale.ENGLISH)); + Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { - final var name = names.nextElement(); - headerNames.add(name); + String name = names.nextElement(); + if (!FORWARDED_HEADER_NAMES.contains(name)) { + headerNames.add(name); + } } - - headerNames.removeAll(FORWARDED_HEADER_NAMES); - return Collections.unmodifiableSet(headerNames); } @@ -196,7 +193,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { if (FORWARDED_HEADER_NAMES.contains(name)) { return null; } - return super.getHeader(name); } @@ -205,7 +201,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { if (FORWARDED_HEADER_NAMES.contains(name)) { return Collections.emptyEnumeration(); } - return super.getHeaders(name); }