Browse Source

Add support for empty router in RouterFunctionDsl

Issue: SPR-17247
pull/1949/head
Sebastien Deleuze 7 years ago
parent
commit
48c660fa41
  1. 7
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt
  2. 5
      spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt

7
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt

@ -546,7 +546,12 @@ open class RouterFunctionDsl(private val init: RouterFunctionDsl.() -> Unit) : ( @@ -546,7 +546,12 @@ open class RouterFunctionDsl(private val init: RouterFunctionDsl.() -> Unit) : (
*/
override fun invoke(): RouterFunction<ServerResponse> {
init()
return routes.reduce(RouterFunction<ServerResponse>::and)
return if (routes.isEmpty()) {
RouterFunction<ServerResponse> { Mono.empty() }
}
else {
routes.reduce(RouterFunction<ServerResponse>::and)
}
}
}

5
spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt

@ -120,6 +120,11 @@ class RouterFunctionDslTests { @@ -120,6 +120,11 @@ class RouterFunctionDslTests {
.verifyComplete()
}
@Test
fun emptyRouter() {
router { }
}
private fun sampleRouter() = router {
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }

Loading…
Cancel
Save