Resolve #26838 This PR fixes following bug.

https://github.com/spring-projects/spring-framework/blob/5b1ab31559798df83f1e8d54d2b754f12c69c14e/spring-webmvc/src/main/kotlin/org/springframework/web/servlet/function/RouterFunctionDsl.kt#L650-L655

https://github.com/spring-projects/spring-framework/blob/5b1ab31559798df83f1e8d54d2b754f12c69c14e/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt#L531-L539

  1. Function filterFunction takes serverRequest and function handler as parameters. (I just named them.)
  2. Function handler also takes serverRequest as parameter.
  3. These DSLs define handler.
  4. Function handlers that these DSLs defined are now using mistakenly filterFunction's serverRequest, not their own serverRequest parameters, which makes their own parameters meaningless.

This bug only exists in Kotlin DSL.

You can see java codes have no problem as follows.

https://github.com/spring-projects/spring-framework/blob/01e50fb60ad0d82f96fe4df6054ed6029e2f6a12/spring-webmvc/src/main/java/org/springframework/web/servlet/function/HandlerFilterFunction.java#L46

https://github.com/spring-projects/spring-framework/blob/01e50fb60ad0d82f96fe4df6054ed6029e2f6a12/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerFilterFunction.java#L48

In java you can override filter something like

ServerRequest newRequest = someOperation(request)
return next.handle(newRequest)

but in Kotlin DSL, even if you write

filter { serverRequest, handlerFunction ->
    val newServerRequest = someOperation(serverRequest)
    handlerFunction(newServerRequest)
}

handlerFunction will use original serverRequest, not the newServerRequest

Comment From: sdeleuze

Thanks for this PR, could you please add related tests for both WebMvc and WebFlux that show a failure with current implementation and would be green with your fix in the 2 RouterFunctionDslTests and CoRouterFunctionDslTests?

Comment From: ShindongLee

@sdeleuze I added tests for Spring MVC (9d0fbbe) and Spring Webflux (b7e6d23). Thank you !

Comment From: ShindongLee

@sdeleuze Do you have any updates or plans for this ...?

Comment From: sdeleuze

Yes it is planned for inclusion in Spring Framework 5.3.7 as mentioned in #26838.

Comment From: sdeleuze

Merged via 07ba95739bf4451742e4ee6b4d4b2d0ee5f701bf (main) and 3ab270e0f13e5dc41d6b9600fb8507c3d48f733c (5.2.x), thanks!