Deprecate pathExtension routing predicates
Closes gh-34103
This commit is contained in:
parent
62d9600cdd
commit
41a9db376d
|
@ -803,8 +803,7 @@ Java::
|
|||
[source,java,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
ClassPathResource index = new ClassPathResource("static/index.html");
|
||||
List<String> extensions = List.of("js", "css", "ico", "png", "jpg", "gif");
|
||||
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extensions::contains)).negate();
|
||||
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).negate();
|
||||
RouterFunction<ServerResponse> redirectToIndex = route()
|
||||
.resource(spaPredicate, index)
|
||||
.build();
|
||||
|
@ -816,9 +815,7 @@ Kotlin::
|
|||
----
|
||||
val redirectToIndex = router {
|
||||
val index = ClassPathResource("static/index.html")
|
||||
val extensions = listOf("js", "css", "ico", "png", "jpg", "gif")
|
||||
val spaPredicate = !(path("/api/**") or path("/error") or
|
||||
pathExtension(extensions::contains))
|
||||
val spaPredicate = !(path("/api/**") or path("/error"))
|
||||
resource(spaPredicate, index)
|
||||
}
|
||||
----
|
||||
|
|
|
@ -782,7 +782,7 @@ Java::
|
|||
----
|
||||
ClassPathResource index = new ClassPathResource("static/index.html");
|
||||
List<String> extensions = List.of("js", "css", "ico", "png", "jpg", "gif");
|
||||
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extensions::contains)).negate();
|
||||
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).negate();
|
||||
RouterFunction<ServerResponse> redirectToIndex = route()
|
||||
.resource(spaPredicate, index)
|
||||
.build();
|
||||
|
@ -794,9 +794,7 @@ Kotlin::
|
|||
----
|
||||
val redirectToIndex = router {
|
||||
val index = ClassPathResource("static/index.html")
|
||||
val extensions = listOf("js", "css", "ico", "png", "jpg", "gif")
|
||||
val spaPredicate = !(path("/api/**") or path("/error") or
|
||||
pathExtension(extensions::contains))
|
||||
val spaPredicate = !(path("/api/**") or path("/error"))
|
||||
resource(spaPredicate, index)
|
||||
}
|
||||
----
|
||||
|
|
|
@ -270,7 +270,12 @@ public abstract class RequestPredicates {
|
|||
* Return a {@code RequestPredicate} that matches if the request's path has the given extension.
|
||||
* @param extension the path extension to match against, ignoring case
|
||||
* @return a predicate that matches if the request's path has the given file extension
|
||||
* @deprecated without replacement to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations and removals already
|
||||
* applied to annotated controllers). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24179</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public static RequestPredicate pathExtension(String extension) {
|
||||
Assert.notNull(extension, "'extension' must not be null");
|
||||
return new PathExtensionPredicate(extension);
|
||||
|
@ -282,7 +287,12 @@ public abstract class RequestPredicates {
|
|||
* @param extensionPredicate the predicate to test against the request path extension
|
||||
* @return a predicate that matches if the given predicate matches against the request's path
|
||||
* file extension
|
||||
* @deprecated without replacement to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations and removals already
|
||||
* applied to annotated controllers). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24179</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public static RequestPredicate pathExtension(Predicate<String> extensionPredicate) {
|
||||
return new PathExtensionPredicate(extensionPredicate);
|
||||
}
|
||||
|
@ -354,7 +364,12 @@ public abstract class RequestPredicates {
|
|||
* Receive notification of a path extension predicate.
|
||||
* @param extension the path extension that makes up the predicate
|
||||
* @see RequestPredicates#pathExtension(String)
|
||||
* @deprecated without replacement to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations and removals already
|
||||
* applied to annotated controllers). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24179</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
void pathExtension(String extension);
|
||||
|
||||
/**
|
||||
|
@ -816,6 +831,7 @@ public abstract class RequestPredicates {
|
|||
}
|
||||
|
||||
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
private static class PathExtensionPredicate implements RequestPredicate {
|
||||
|
||||
private final Predicate<String> extensionPredicate;
|
||||
|
|
|
@ -102,6 +102,8 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
|
|||
this.builder.append(pattern);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
@Override
|
||||
public void pathExtension(String extension) {
|
||||
this.builder.append(String.format("*.%s", extension));
|
||||
|
|
|
@ -507,6 +507,11 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
|
|||
* Route to the given handler function if the given pathExtension predicate applies.
|
||||
* @see RouterFunctions.route
|
||||
*/
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
fun pathExtension(extension: String, f: suspend (ServerRequest) -> ServerResponse) {
|
||||
builder.add(RouterFunctions.route(RequestPredicates.pathExtension(extension), asHandlerFunction(f)))
|
||||
}
|
||||
|
@ -516,12 +521,22 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
|
|||
* @param extension the path extension to match against, ignoring case
|
||||
* @return a predicate that matches if the request's path has the given file extension
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(extension: String): RequestPredicate = RequestPredicates.pathExtension(extension)
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given pathExtension predicate applies.
|
||||
* @see RouterFunctions.route
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(predicate: (String?) -> Boolean, f: suspend (ServerRequest) -> ServerResponse) {
|
||||
builder.add(RouterFunctions.route(RequestPredicates.pathExtension(predicate), asHandlerFunction(f)))
|
||||
}
|
||||
|
@ -529,8 +544,12 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
|
|||
/**
|
||||
* Return a [RequestPredicate] that matches if the request's path matches the given
|
||||
* predicate.
|
||||
* @see RequestPredicates.pathExtension
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(predicate: (String?) -> Boolean): RequestPredicate =
|
||||
RequestPredicates.pathExtension(predicate)
|
||||
|
||||
|
|
|
@ -554,6 +554,11 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
* Route to the given handler function if the given pathExtension predicate applies.
|
||||
* @see RouterFunctions.route
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(extension: String, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.add(RouterFunctions.route(RequestPredicates.pathExtension(extension)) { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
@ -563,12 +568,22 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
* @param extension the path extension to match against, ignoring case
|
||||
* @return a predicate that matches if the request's path has the given file extension
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(extension: String): RequestPredicate = RequestPredicates.pathExtension(extension)
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given pathExtension predicate applies.
|
||||
* @see RouterFunctions.route
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(predicate: (String?) -> Boolean, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.add(RouterFunctions.route(RequestPredicates.pathExtension(predicate)) { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
@ -576,8 +591,12 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
/**
|
||||
* Return a [RequestPredicate] that matches if the request's path matches the given
|
||||
* predicate.
|
||||
* @see RequestPredicates.pathExtension
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(predicate: (String?) -> Boolean): RequestPredicate =
|
||||
RequestPredicates.pathExtension(predicate)
|
||||
|
||||
|
|
|
@ -296,6 +296,7 @@ class RequestPredicatesTests {
|
|||
assertThat(predicate.test(request)).isFalse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Test
|
||||
void pathExtension() {
|
||||
RequestPredicate predicate = RequestPredicates.pathExtension("txt");
|
||||
|
@ -319,6 +320,7 @@ class RequestPredicatesTests {
|
|||
assertThat(predicate.test(request)).isFalse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Test
|
||||
void pathExtensionPredicate() {
|
||||
List<String> extensions = List.of("foo", "bar");
|
||||
|
|
|
@ -29,7 +29,6 @@ import static org.springframework.web.reactive.function.server.RequestPredicates
|
|||
import static org.springframework.web.reactive.function.server.RequestPredicates.method;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.methods;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.path;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.pathExtension;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.queryParam;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
|
||||
|
@ -69,8 +68,6 @@ class ToStringVisitorTests {
|
|||
|
||||
testPredicate(path("/foo"), "/foo");
|
||||
|
||||
testPredicate(pathExtension("foo"), "*.foo");
|
||||
|
||||
testPredicate(contentType(MediaType.APPLICATION_JSON), "Content-Type: application/json");
|
||||
|
||||
ToStringVisitor visitor = new ToStringVisitor();
|
||||
|
|
|
@ -333,6 +333,7 @@ class CoRouterFunctionDslTests {
|
|||
null
|
||||
}
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
GET(pathExtension { it == "properties" }) {
|
||||
ok().bodyValueAndAwait("foo=bar")
|
||||
}
|
||||
|
|
|
@ -265,6 +265,7 @@ class RouterFunctionDslTests {
|
|||
Mono.empty()
|
||||
}
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
GET(pathExtension { it == "properties" }) {
|
||||
ok().bodyValue("foo=bar")
|
||||
}
|
||||
|
|
|
@ -269,7 +269,12 @@ public abstract class RequestPredicates {
|
|||
* Return a {@code RequestPredicate} that matches if the request's path has the given extension.
|
||||
* @param extension the path extension to match against, ignoring case
|
||||
* @return a predicate that matches if the request's path has the given file extension
|
||||
* @deprecated without replacement to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations and removals already
|
||||
* applied to annotated controllers). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24179</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public static RequestPredicate pathExtension(String extension) {
|
||||
Assert.notNull(extension, "'extension' must not be null");
|
||||
return new PathExtensionPredicate(extension);
|
||||
|
@ -281,7 +286,12 @@ public abstract class RequestPredicates {
|
|||
* @param extensionPredicate the predicate to test against the request path extension
|
||||
* @return a predicate that matches if the given predicate matches against the request's path
|
||||
* file extension
|
||||
* @deprecated without replacement to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations and removals already
|
||||
* applied to annotated controllers). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24179</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public static RequestPredicate pathExtension(Predicate<String> extensionPredicate) {
|
||||
return new PathExtensionPredicate(extensionPredicate);
|
||||
}
|
||||
|
@ -352,7 +362,12 @@ public abstract class RequestPredicates {
|
|||
* Receive notification of a path extension predicate.
|
||||
* @param extension the path extension that makes up the predicate
|
||||
* @see RequestPredicates#pathExtension(String)
|
||||
* @deprecated without replacement to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations and removals already
|
||||
* applied to annotated controllers). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24179</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
void pathExtension(String extension);
|
||||
|
||||
/**
|
||||
|
@ -814,6 +829,7 @@ public abstract class RequestPredicates {
|
|||
}
|
||||
|
||||
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
private static class PathExtensionPredicate implements RequestPredicate {
|
||||
|
||||
private final Predicate<String> extensionPredicate;
|
||||
|
|
|
@ -101,6 +101,8 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi
|
|||
this.builder.append(pattern);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
@Override
|
||||
public void pathExtension(String extension) {
|
||||
this.builder.append(String.format("*.%s", extension));
|
||||
|
|
|
@ -549,6 +549,11 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
* Route to the given handler function if the given pathExtension predicate applies.
|
||||
* @see RouterFunctions.route
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(extension: String, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.add(RouterFunctions.route(RequestPredicates.pathExtension(extension), HandlerFunction(f)))
|
||||
}
|
||||
|
@ -558,12 +563,22 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
* @param extension the path extension to match against, ignoring case
|
||||
* @return a predicate that matches if the request's path has the given file extension
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(extension: String): RequestPredicate = RequestPredicates.pathExtension(extension)
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given pathExtension predicate applies.
|
||||
* @see RouterFunctions.route
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(predicate: (String?) -> Boolean, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.add(RouterFunctions.route(RequestPredicates.pathExtension(predicate), HandlerFunction(f)))
|
||||
}
|
||||
|
@ -573,6 +588,11 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
* predicate.
|
||||
* @see RequestPredicates.pathExtension
|
||||
*/
|
||||
@Suppress("removal", "DEPRECATION")
|
||||
@Deprecated("without replacement to discourage use of path extensions for request mapping and for" +
|
||||
"content negotiation (with similar deprecations and removals already applied to" +
|
||||
"annotated controllers). For further context, please read issue " +
|
||||
"https://github.com/spring-projects/spring-framework/issues/24179", replaceWith = ReplaceWith("None"))
|
||||
fun pathExtension(predicate: (String?) -> Boolean): RequestPredicate =
|
||||
RequestPredicates.pathExtension(predicate)
|
||||
|
||||
|
|
|
@ -223,6 +223,7 @@ class RequestPredicatesTests {
|
|||
assertThat(predicate.test(request)).isFalse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Test
|
||||
void pathExtension() {
|
||||
RequestPredicate predicate = RequestPredicates.pathExtension("txt");
|
||||
|
@ -237,6 +238,7 @@ class RequestPredicatesTests {
|
|||
assertThat(predicate.test(initRequest("GET", "/file"))).isFalse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Test
|
||||
void pathExtensionPredicate() {
|
||||
List<String> extensions = List.of("foo", "bar");
|
||||
|
|
|
@ -29,7 +29,6 @@ import static org.springframework.web.servlet.function.RequestPredicates.method;
|
|||
import static org.springframework.web.servlet.function.RequestPredicates.methods;
|
||||
import static org.springframework.web.servlet.function.RequestPredicates.param;
|
||||
import static org.springframework.web.servlet.function.RequestPredicates.path;
|
||||
import static org.springframework.web.servlet.function.RequestPredicates.pathExtension;
|
||||
import static org.springframework.web.servlet.function.RouterFunctions.route;
|
||||
|
||||
/**
|
||||
|
@ -61,6 +60,7 @@ class ToStringVisitorTests {
|
|||
assertThat(result).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Test
|
||||
void predicates() {
|
||||
testPredicate(methods(HttpMethod.GET), "GET");
|
||||
|
@ -68,8 +68,6 @@ class ToStringVisitorTests {
|
|||
|
||||
testPredicate(path("/foo"), "/foo");
|
||||
|
||||
testPredicate(pathExtension("foo"), "*.foo");
|
||||
|
||||
testPredicate(contentType(MediaType.APPLICATION_JSON), "Content-Type: application/json");
|
||||
|
||||
ToStringVisitor visitor = new ToStringVisitor();
|
||||
|
|
|
@ -192,6 +192,7 @@ class RouterFunctionDslTests {
|
|||
null
|
||||
}
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
GET(pathExtension { it == "properties" }) {
|
||||
ok().body("foo=bar")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue