From abe381488a1da1f48aff91e374a27937ba49ae90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 13 Feb 2024 14:50:49 +0100 Subject: [PATCH] Add missing RequestPredicate variants in coRouter Closes gh-32256 --- .../function/server/CoRouterFunctionDsl.kt | 84 +++++++++++++++++-- .../server/CoRouterFunctionDslTests.kt | 2 +- 2 files changed, 78 insertions(+), 8 deletions(-) diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt index 16e67404f03..868ab106d9b 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt @@ -170,7 +170,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `GET` requests - * that match the given pattern. + * that match the given predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun GET(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.GET(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `GET` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 @@ -197,7 +207,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `HEAD` requests - * that match the given pattern. + * that match the given pattern and predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun HEAD(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.HEAD(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `HEAD` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 @@ -224,7 +244,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `POST` requests - * that match the given pattern. + * that match the given predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun POST(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.POST(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `POST` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 @@ -251,7 +281,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `PUT` requests - * that match the given pattern. + * that match the given predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun PUT(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.PUT(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `PUT` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 @@ -278,7 +318,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `PATCH` requests - * that match the given pattern. + * that match the given pattern and predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun PATCH(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.PATCH(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `PATCH` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 @@ -307,7 +357,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `DELETE` requests - * that match the given pattern. + * that match the given predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun DELETE(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.DELETE(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `DELETE` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 @@ -336,7 +396,17 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct /** * Adds a route to the given handler function that handles all HTTP `OPTIONS` requests - * that match the given pattern. + * that match the given predicate. + * @param predicate predicate to match + * @since 6.1.4 + */ + fun OPTIONS(predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) { + builder.OPTIONS(predicate, asHandlerFunction(f)) + } + + /** + * Adds a route to the given handler function that handles all HTTP `OPTIONS` requests + * that match the given pattern and predicate. * @param pattern the pattern to match to * @param predicate additional predicate to match * @since 5.2 diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDslTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDslTests.kt index db523a093dc..69448536121 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDslTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDslTests.kt @@ -333,7 +333,7 @@ class CoRouterFunctionDslTests { null } } - GET("/**", pathExtension { it == "properties" }) { + GET(pathExtension { it == "properties" }) { ok().bodyValueAndAwait("foo=bar") } path("/baz", ::handle)