Fix parameter bug of handler inside the filterFunction DSL
Co-authored-by: hojongs <hojong.jjh@gmail.com> Co-authored-by: bjh970913 <bjh970913@gmail.com> Closes gh-26838
This commit is contained in:
committed by
Sébastien Deleuze
parent
0468ef46ac
commit
07ba95739b
@@ -152,6 +152,16 @@ class CoRouterFunctionDslTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filtering() {
|
||||
val mockRequest = get("https://example.com/filter").build()
|
||||
val request = DefaultServerRequest(MockServerWebExchange.from(mockRequest), emptyList())
|
||||
StepVerifier.create(sampleRouter().route(request).flatMap { it.handle(request) })
|
||||
.expectNextMatches { response ->
|
||||
response.headers().getFirst("foo") == "bar"
|
||||
}
|
||||
.verifyComplete()
|
||||
}
|
||||
|
||||
private fun sampleRouter() = coRouter {
|
||||
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
|
||||
@@ -186,6 +196,18 @@ class CoRouterFunctionDslTests {
|
||||
path("/baz", ::handle)
|
||||
GET("/rendering") { RenderingResponse.create("index").buildAndAwait() }
|
||||
add(otherRouter)
|
||||
add(filterRouter)
|
||||
}
|
||||
|
||||
private val filterRouter = coRouter {
|
||||
"/filter" { request ->
|
||||
ok().header("foo", request.headers().firstHeader("foo")).buildAndAwait()
|
||||
}
|
||||
|
||||
filter { request, next ->
|
||||
val newRequest = ServerRequest.from(request).apply { header("foo", "bar") }.build()
|
||||
next(newRequest)
|
||||
}
|
||||
}
|
||||
|
||||
private val otherRouter = router {
|
||||
|
||||
Reference in New Issue
Block a user