File tree Expand file tree Collapse file tree 6 files changed +40
-6
lines changed
main/kotlin/org/springframework/web/reactive/function/server
test/kotlin/org/springframework/web/reactive/function/server
main/kotlin/org/springframework/web/servlet/function
test/kotlin/org/springframework/web/servlet/function Expand file tree Collapse file tree 6 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -452,7 +452,7 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
452
452
* Route to the given handler function if the given pathExtension predicate applies.
453
453
* @see RouterFunctions.route
454
454
*/
455
- fun pathExtension (predicate : (String ) -> Boolean , f : suspend (ServerRequest ) -> ServerResponse ) {
455
+ fun pathExtension (predicate : (String? ) -> Boolean , f : suspend (ServerRequest ) -> ServerResponse ) {
456
456
builder.add(RouterFunctions .route(RequestPredicates .pathExtension(predicate), asHandlerFunction(f)))
457
457
}
458
458
@@ -461,7 +461,7 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
461
461
* predicate.
462
462
* @see RequestPredicates.pathExtension
463
463
*/
464
- fun pathExtension (predicate : (String ) -> Boolean ): RequestPredicate =
464
+ fun pathExtension (predicate : (String? ) -> Boolean ): RequestPredicate =
465
465
RequestPredicates .pathExtension(predicate)
466
466
467
467
/* *
Original file line number Diff line number Diff line change @@ -569,7 +569,7 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
569
569
* Route to the given handler function if the given pathExtension predicate applies.
570
570
* @see RouterFunctions.route
571
571
*/
572
- fun pathExtension (predicate : (String ) -> Boolean , f : (ServerRequest ) -> Mono <out ServerResponse >) {
572
+ fun pathExtension (predicate : (String? ) -> Boolean , f : (ServerRequest ) -> Mono <out ServerResponse >) {
573
573
builder.add(RouterFunctions .route(RequestPredicates .pathExtension(predicate), HandlerFunction { f(it).cast(ServerResponse ::class .java) }))
574
574
}
575
575
@@ -578,7 +578,7 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
578
578
* predicate.
579
579
* @see RequestPredicates.pathExtension
580
580
*/
581
- fun pathExtension (predicate : (String ) -> Boolean ): RequestPredicate =
581
+ fun pathExtension (predicate : (String? ) -> Boolean ): RequestPredicate =
582
582
RequestPredicates .pathExtension(predicate)
583
583
584
584
/* *
Original file line number Diff line number Diff line change @@ -112,6 +112,15 @@ class CoRouterFunctionDslTests {
112
112
.verifyComplete()
113
113
}
114
114
115
+ @Test
116
+ fun pathExtension () {
117
+ val mockRequest = get(" https://example.com/test.properties" ).build()
118
+ val request = DefaultServerRequest (MockServerWebExchange .from(mockRequest), emptyList())
119
+ StepVerifier .create(sampleRouter().route(request))
120
+ .expectNextCount(1 )
121
+ .verifyComplete()
122
+ }
123
+
115
124
@Test
116
125
fun resource () {
117
126
val mockRequest = get(" https://example.com/response2.txt" ).build()
@@ -324,6 +333,9 @@ class CoRouterFunctionDslTests {
324
333
null
325
334
}
326
335
}
336
+ GET (" /**" , pathExtension { it == " properties" }) {
337
+ ok().bodyValueAndAwait(" foo=bar" )
338
+ }
327
339
path(" /baz" , ::handle)
328
340
GET (" /rendering" ) { RenderingResponse .create(" index" ).buildAndAwait() }
329
341
add(otherRouter)
Original file line number Diff line number Diff line change @@ -110,6 +110,15 @@ class RouterFunctionDslTests {
110
110
.verifyComplete()
111
111
}
112
112
113
+ @Test
114
+ fun pathExtension () {
115
+ val mockRequest = get(" https://example.com/test.properties" ).build()
116
+ val request = DefaultServerRequest (MockServerWebExchange .from(mockRequest), emptyList())
117
+ StepVerifier .create(sampleRouter().route(request))
118
+ .expectNextCount(1 )
119
+ .verifyComplete()
120
+ }
121
+
113
122
@Test
114
123
fun resource () {
115
124
val mockRequest = get(" https://example.com/response2.txt" ).build()
@@ -256,6 +265,9 @@ class RouterFunctionDslTests {
256
265
Mono .empty()
257
266
}
258
267
}
268
+ GET (pathExtension { it == " properties" }) {
269
+ ok().bodyValue(" foo=bar" )
270
+ }
259
271
path(" /baz" , ::handle)
260
272
GET (" /rendering" ) { RenderingResponse .create(" index" ).build() }
261
273
add(otherRouter)
Original file line number Diff line number Diff line change @@ -564,7 +564,7 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
564
564
* Route to the given handler function if the given pathExtension predicate applies.
565
565
* @see RouterFunctions.route
566
566
*/
567
- fun pathExtension (predicate : (String ) -> Boolean , f : (ServerRequest ) -> ServerResponse ) {
567
+ fun pathExtension (predicate : (String? ) -> Boolean , f : (ServerRequest ) -> ServerResponse ) {
568
568
builder.add(RouterFunctions .route(RequestPredicates .pathExtension(predicate), HandlerFunction (f)))
569
569
}
570
570
@@ -573,7 +573,7 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
573
573
* predicate.
574
574
* @see RequestPredicates.pathExtension
575
575
*/
576
- fun pathExtension (predicate : (String ) -> Boolean ): RequestPredicate =
576
+ fun pathExtension (predicate : (String? ) -> Boolean ): RequestPredicate =
577
577
RequestPredicates .pathExtension(predicate)
578
578
579
579
/* *
Original file line number Diff line number Diff line change @@ -88,6 +88,13 @@ class RouterFunctionDslTests {
88
88
assertThat(sampleRouter().route(request).isPresent).isTrue()
89
89
}
90
90
91
+ @Test
92
+ fun pathExtension () {
93
+ val servletRequest = PathPatternsTestUtils .initRequest(" GET" , " /test.properties" , true )
94
+ val request = DefaultServerRequest (servletRequest, emptyList())
95
+ assertThat(sampleRouter().route(request).isPresent).isTrue()
96
+ }
97
+
91
98
@Test
92
99
fun resource () {
93
100
val servletRequest = PathPatternsTestUtils .initRequest(" GET" ," /response2.txt" , true )
@@ -185,6 +192,9 @@ class RouterFunctionDslTests {
185
192
null
186
193
}
187
194
}
195
+ GET (pathExtension { it == " properties" }) {
196
+ ok().body(" foo=bar" )
197
+ }
188
198
path(" /baz" , ::handle)
189
199
GET (" /rendering" ) { RenderingResponse .create(" index" ).build() }
190
200
add(otherRouter)
You can’t perform that action at this time.
0 commit comments