From 90e2d315377812b31786aa6a6a007fa5450ca399 Mon Sep 17 00:00:00 2001 From: Tommas Yuan Date: Mon, 21 Mar 2022 09:57:12 +0800 Subject: [PATCH 1/4] rename test case name for issue 2541 --- .../gateway/filter/NettyRoutingFilterIntegrationTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java index 5164949b..52d4d6c5 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java @@ -133,7 +133,8 @@ public class NettyRoutingFilterIntegrationTests extends BaseWebClientTests { } @Test - public void testHeadersAreClearedOnFallback() { + // gh-2541 + public void shouldMergeResponseHeadersFromUpstreamWithCreatedByGateway() { String header = "X-Test-SHOULD-MERGED-HEADER"; String gatewayHeaderValue = "value-from-gateway"; String upstreamHeaderValue = "value-from-upstream"; From 520532b6146bae3a0c030a5fe4b603963913dd80 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Thu, 12 Jan 2023 13:14:43 -0500 Subject: [PATCH 2/4] removes comments --- .../factory/SecureHeadersProperties.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersProperties.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersProperties.java index e3fc3d3a..6802575a 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersProperties.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersProperties.java @@ -35,15 +35,12 @@ public class SecureHeadersProperties { /** * Strict transport security header default. */ - public static final String STRICT_TRANSPORT_SECURITY_HEADER_DEFAULT = "max-age=631138519"; // ; - // includeSubDomains - // preload") + public static final String STRICT_TRANSPORT_SECURITY_HEADER_DEFAULT = "max-age=631138519"; /** * Frame Options header default. */ - public static final String X_FRAME_OPTIONS_HEADER_DEFAULT = "DENY"; // SAMEORIGIN = - // ALLOW-FROM + public static final String X_FRAME_OPTIONS_HEADER_DEFAULT = "DENY"; /** * Content-Type Options header default. @@ -53,19 +50,7 @@ public class SecureHeadersProperties { /** * Referrer Policy header default. */ - public static final String REFERRER_POLICY_HEADER_DEFAULT = "no-referrer"; // no-referrer-when-downgrade - // = - // origin - // = - // origin-when-cross-origin - // = - // same-origin - // = - // strict-origin - // = - // strict-origin-when-cross-origin - // = - // unsafe-url + public static final String REFERRER_POLICY_HEADER_DEFAULT = "no-referrer"; /** * Content-Security Policy header default. From ee5ad6f462d333df25aa919c1305acccea94953a Mon Sep 17 00:00:00 2001 From: zhenqiangyi <835576511@qq.com> Date: Mon, 21 Mar 2022 15:29:42 +0800 Subject: [PATCH 3/4] Changes to use ThreadLocalRandom Usually, multiple threads accessing the same random object will have some performance problems, so we can use ThreadLocalRandom by default Fixes gh-2565 --- .../gateway/filter/WeightCalculatorWebFilter.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java index 9353c446..f4aeec98 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -63,7 +64,7 @@ public class WeightCalculatorWebFilter implements WebFilter, Ordered, SmartAppli private final ConfigurationService configurationService; - private Random random = new Random(); + private Random random = null; private int order = WEIGHT_CALC_FILTER_ORDER; @@ -231,7 +232,13 @@ public class WeightCalculatorWebFilter implements WebFilter, Ordered, SmartAppli continue; // nothing we can do, but this is odd } - double r = this.random.nextDouble(); + /* + * Usually, multiple threads accessing the same random object will have some performance problems, + * so we can use ThreadLocalRandom by default + */ + Random useRandom = this.random; + useRandom = useRandom == null ? ThreadLocalRandom.current() : useRandom; + double r = useRandom.nextDouble(); List ranges = config.ranges; From ec76763404bd829b06dc687d6e7bcbbfd4b0d939 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Thu, 12 Jan 2023 13:26:40 -0500 Subject: [PATCH 4/4] =?UTF-8?q?formatting=CB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud/gateway/filter/WeightCalculatorWebFilter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java index f4aeec98..4333043a 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java @@ -233,8 +233,8 @@ public class WeightCalculatorWebFilter implements WebFilter, Ordered, SmartAppli } /* - * Usually, multiple threads accessing the same random object will have some performance problems, - * so we can use ThreadLocalRandom by default + * Usually, multiple threads accessing the same random object will have some + * performance problems, so we can use ThreadLocalRandom by default */ Random useRandom = this.random; useRandom = useRandom == null ? ThreadLocalRandom.current() : useRandom;