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
- Function
filterFunctiontakesserverRequestand functionhandleras parameters. (I just name it second parameter offilterFunctionashandler.) - Function
handleralso takesserverRequestas parameter. - These DSLs define
handler. - Function
handlers that these DSLs defined are now using mistakenlyfilterFunction'sserverRequest, not their ownserverRequestparameters, 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
Good catch, to be backported on 5.2.x as well. I will be able to merge the proposed fix with additional tests asked here, thanks.
Comment From: ShindongLee
@sdeleuze I added tests. Thank you !