Skip to content

Commit e99210e

Browse files
committed
Merge branch '4.2.x' into 4.3.x
2 parents 78a294b + 9fa9985 commit e99210e

File tree

10 files changed

+42
-22
lines changed

10 files changed

+42
-22
lines changed

docs/modules/ROOT/partials/_configprops.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@
135135
|spring.cloud.gateway.loadbalancer.use404 | `+++false+++` |
136136
|spring.cloud.gateway.metrics | |
137137
|spring.cloud.gateway.metrics.enabled | `+++false+++` | Enables the collection of metrics data.
138+
|spring.cloud.gateway.metrics.path-tags.enabled | `+++false+++` | Enables the gateway path tag provider.
138139
|spring.cloud.gateway.metrics.prefix | `+++spring.cloud.gateway+++` | The prefix of all metrics emitted by gateway.
139140
|spring.cloud.gateway.metrics.tags | | Tags map that added to metrics.
141+
|spring.cloud.gateway.metrics.tags.path.enabled | `+++false+++` | Enables the gateway path tag provider.
140142
|spring.cloud.gateway.mvc.form-filter.enabled | `+++true+++` | Enables the form-filter.
141143
|spring.cloud.gateway.mvc.forwarded-request-headers-filter.enabled | `+++true+++` | Enables the forwarded-request-headers-filter.
142144
|spring.cloud.gateway.mvc.http-client.connect-timeout | | The HttpClient connect timeout.

spring-cloud-gateway-server-mvc/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@
155155
<artifactId>rabbitmq</artifactId>
156156
<scope>test</scope>
157157
</dependency>
158+
<dependency>
159+
<groupId>org.springframework.boot</groupId>
160+
<artifactId>spring-boot-starter-security</artifactId>
161+
<scope>test</scope>
162+
</dependency>
158163
</dependencies>
159164

160165
<profiles>

spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/common/MvcUtils.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.Map;
3434
import java.util.Optional;
3535

36+
import jakarta.servlet.http.HttpServletRequest;
37+
import jakarta.servlet.http.HttpServletRequestWrapper;
3638
import org.apache.commons.logging.Log;
3739
import org.apache.commons.logging.LogFactory;
3840

@@ -123,6 +125,21 @@ public static <T> Optional<T> cacheAndReadBody(ServerRequest request, Class<T> t
123125
return readBody(request, rawBody, toClass);
124126
}
125127

128+
/**
129+
* Unwraps an HttpServletRequest to get to the innermost request. This is necessary to
130+
* ensure attributes are set on the actual request object rather than on wrapper
131+
* instances that may not propagate attribute changes.
132+
* @param request the request to unwrap
133+
* @return the innermost HttpServletRequest
134+
*/
135+
private static HttpServletRequest unwrapRequest(HttpServletRequest request) {
136+
HttpServletRequest unwrapped = request;
137+
while (unwrapped instanceof HttpServletRequestWrapper wrapper) {
138+
unwrapped = (HttpServletRequest) wrapper.getRequest();
139+
}
140+
return unwrapped;
141+
}
142+
126143
public static ByteArrayInputStream cacheBody(ServerRequest request) {
127144
try {
128145
byte[] bytes = StreamUtils.copyToByteArray(request.servletRequest().getInputStream());
@@ -183,7 +200,12 @@ public static <T> T getAttribute(ServerRequest request, String key) {
183200
if (request.attributes().containsKey(key)) {
184201
return (T) request.attributes().get(key);
185202
}
186-
return (T) getGatewayAttributes(request).get(key);
203+
T gatewayAttr = (T) getGatewayAttributes(request).get(key);
204+
if (gatewayAttr != null) {
205+
return gatewayAttr;
206+
}
207+
// Fallback to servlet request attributes for compatibility with request wrappers
208+
return (T) request.servletRequest().getAttribute(key);
187209
}
188210

189211
@SuppressWarnings("unchecked")
@@ -207,8 +229,13 @@ public static Map<String, Object> getUriTemplateVariables(ServerRequest request)
207229
}
208230

209231
public static void putAttribute(ServerRequest request, String key, Object value) {
232+
// Also set on the unwrapped servlet request to ensure persistence through
233+
// wrappers like Spring's AttributesPreservingRequest
234+
HttpServletRequest unwrapped = unwrapRequest((HttpServletRequest) request.servletRequest());
210235
request.attributes().put(key, value);
211236
getGatewayAttributes(request).put(key, value);
237+
unwrapped.setAttribute(key, value);
238+
212239
}
213240

214241
@SuppressWarnings("unchecked")

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ void logsArtifactDeprecatedWarning(CapturedOutput output) {
10321032
@EnableAutoConfiguration
10331033
@LoadBalancerClient(name = "httpbin", configuration = TestLoadBalancerConfig.Httpbin.class)
10341034
@Import(PermitAllSecurityConfiguration.class)
1035-
protected static class TestConfiguration extends WebMvcConfigurationSupport {
1035+
protected static class TestConfiguration {
10361036

10371037
@Bean
10381038
StaticPortController staticPortController() {
@@ -1049,26 +1049,6 @@ EventController eventController() {
10491049
return new EventController();
10501050
}
10511051

1052-
// TODO This is needed to work around
1053-
// https://github.com/spring-cloud/spring-cloud-gateway/issues/3816
1054-
// which results from Spring Security being on the classpath. Once we can address
1055-
// this issue we should
1056-
// remove this bean and no longer extend WebMvcConfigurationSupport in this
1057-
// configuration class
1058-
@Bean
1059-
@Lazy
1060-
@Override
1061-
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
1062-
return new HandlerMappingIntrospector() {
1063-
@Override
1064-
public Filter createCacheFilter() {
1065-
return (request, response, chain) -> {
1066-
chain.doFilter(request, response);
1067-
};
1068-
}
1069-
};
1070-
}
1071-
10721052
@Bean
10731053
public AsyncProxyManager<String> caffeineProxyManager() {
10741054
Caffeine<String, RemoteBucketState> builder = (Caffeine) Caffeine.newBuilder().maximumSize(100);

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/config/GatewayMvcPropertiesBeanDefinitionRegistrarTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
3333
import org.springframework.boot.test.util.TestPropertyValues;
3434
import org.springframework.cloud.context.refresh.ContextRefresher;
35+
import org.springframework.cloud.gateway.server.mvc.PermitAllSecurityConfiguration;
3536
import org.springframework.cloud.gateway.server.mvc.common.MvcUtils;
3637
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
3738
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/AfterFilterFunctionsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.boot.SpringBootConfiguration;
2626
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2727
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.cloud.gateway.server.mvc.PermitAllSecurityConfiguration;
2829
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
2930
import org.springframework.cloud.gateway.server.mvc.test.HttpbinUriResolver;
3031
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/BodyFilterFunctionsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.boot.SpringBootConfiguration;
2525
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2626
import org.springframework.boot.test.context.SpringBootTest;
27+
import org.springframework.cloud.gateway.server.mvc.PermitAllSecurityConfiguration;
2728
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
2829
import org.springframework.cloud.gateway.server.mvc.test.HttpbinUriResolver;
2930
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/RetryFilterFunctionTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.test.context.SpringBootTest;
3131
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
3232
import org.springframework.boot.test.web.server.LocalServerPort;
33+
import org.springframework.cloud.gateway.server.mvc.PermitAllSecurityConfiguration;
3334
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
3435
import org.springframework.cloud.gateway.server.mvc.test.LocalServerPortUriResolver;
3536
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/StripPrefixStaticPortTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2727
import org.springframework.boot.test.context.SpringBootTest;
2828
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
29+
import org.springframework.cloud.gateway.server.mvc.PermitAllSecurityConfiguration;
2930
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
3031
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
3132
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;

spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/WeightRequestPredicateIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.boot.SpringBootConfiguration;
2525
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2626
import org.springframework.boot.test.context.SpringBootTest;
27+
import org.springframework.cloud.gateway.server.mvc.PermitAllSecurityConfiguration;
2728
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
2829
import org.springframework.cloud.gateway.server.mvc.test.HttpbinUriResolver;
2930
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;

0 commit comments

Comments
 (0)