Remove WebFlux trailing slash match

See gh-34036
This commit is contained in:
rstoyanchev 2024-12-13 14:10:19 +00:00
parent 4fd368b1af
commit 32db1a1680
5 changed files with 1 additions and 111 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@ -21,7 +21,6 @@ import java.util.Map;
import java.util.function.Predicate;
import org.springframework.lang.Nullable;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* Assist with configuring {@code HandlerMapping}'s with path matching options.
@ -32,10 +31,6 @@ import org.springframework.web.util.pattern.PathPatternParser;
*/
public class PathMatchConfigurer {
@Nullable
private Boolean trailingSlashMatch;
@Nullable
private Boolean caseSensitiveMatch;
@ -53,20 +48,6 @@ public class PathMatchConfigurer {
return this;
}
/**
* Whether to match to URLs irrespective of the presence of a trailing slash.
* If enabled a method mapped to "/users" also matches to "/users/".
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
* order to support the deprecation of the property.
* @deprecated as of 6.0, see
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
@Deprecated(since = "6.0")
public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) {
this.trailingSlashMatch = trailingSlashMatch;
return this;
}
/**
* Configure a path prefix to apply to matching controller methods.
* <p>Prefixes are used to enrich the mappings of every {@code @RequestMapping}
@ -87,12 +68,6 @@ public class PathMatchConfigurer {
}
@Nullable
@Deprecated
protected Boolean isUseTrailingSlashMatch() {
return this.trailingSlashMatch;
}
@Nullable
protected Boolean isUseCaseSensitiveMatch() {
return this.caseSensitiveMatch;

View File

@ -154,13 +154,8 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
return mapping;
}
@SuppressWarnings("deprecation")
private void configureAbstractHandlerMapping(AbstractHandlerMapping mapping, PathMatchConfigurer configurer) {
mapping.setCorsConfigurations(getCorsConfigurations());
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
if (useTrailingSlashMatch != null) {
mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
}
Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
if (useCaseSensitiveMatch != null) {
mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);

View File

@ -85,24 +85,6 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
this.patternParser.setCaseSensitive(caseSensitiveMatch);
}
/**
* Shortcut method for setting the same property on the underlying pattern
* parser in use. For more details see:
* <ul>
* <li>{@link #getPathPatternParser()} -- the underlying pattern parser
* <li>{@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)} --
* the trailing slash option, including its default value.
* </ul>
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
* order to support the deprecation of the property.
* @deprecated as of 6.0, see
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
@Deprecated(since = "6.0")
public void setUseTrailingSlashMatch(boolean trailingSlashMatch) {
this.patternParser.setMatchOptionalTrailingSeparator(trailingSlashMatch);
}
/**
* Return the {@link PathPatternParser} instance that is used for
* {@link #setCorsConfigurations(Map) CORS configuration checks}.

View File

@ -16,7 +16,6 @@
package org.springframework.web.reactive.config;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.security.Principal;
import java.util.Collections;
@ -48,7 +47,6 @@ import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -71,9 +69,7 @@ import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebHandler;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.assertj.core.api.Assertions.assertThat;
@ -87,7 +83,6 @@ import static org.springframework.http.MediaType.APPLICATION_PROTOBUF;
import static org.springframework.http.MediaType.APPLICATION_XML;
import static org.springframework.http.MediaType.IMAGE_PNG;
import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get;
/**
* Tests for {@link WebFluxConfigurationSupport}.
@ -96,31 +91,6 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
*/
class WebFluxConfigurationSupportTests {
@Test
void requestMappingHandlerMapping() {
ApplicationContext context = loadConfig(WebFluxConfig.class);
Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
assertThat(field).isNotNull();
ReflectionUtils.makeAccessible(field);
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertThat(mapping).isNotNull();
assertThat(mapping.getOrder()).isEqualTo(0);
PathPatternParser patternParser = mapping.getPathPatternParser();
assertThat(patternParser).hasFieldOrPropertyWithValue("matchOptionalTrailingSeparator", false);
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
assertThat(mapping.getContentTypeResolver()).isSameAs(resolver);
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
assertThat(resolver.resolveMediaTypes(exchange))
.isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
@Test
void customPathMatchConfig() {
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);

View File

@ -104,38 +104,6 @@ class PatternsRequestConditionTests {
assertThat(match).isEqualTo(expected);
}
@Test
@SuppressWarnings("deprecation")
public void matchTrailingSlash() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
PathPatternParser patternParser = new PathPatternParser();
patternParser.setMatchOptionalTrailingSeparator(true);
PatternsRequestCondition condition = new PatternsRequestCondition(patternParser.parse("/foo"));
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next().getPatternString())
.as("Should match by default")
.isEqualTo("/foo");
condition = new PatternsRequestCondition(patternParser.parse("/foo"));
match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next().getPatternString())
.as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)")
.isEqualTo("/foo");
PathPatternParser parser = new PathPatternParser();
parser.setMatchOptionalTrailingSeparator(false);
condition = new PatternsRequestCondition(parser.parse("/foo"));
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));
assertThat(match).isNull();
}
@Test
void matchPatternContainsExtension() {
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");