Inherit parent context in coRouter DSL
This commit also allows context override, as it is useful for the nested router use case. Closes gh-31831
This commit is contained in:
@@ -144,7 +144,7 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
|
||||
* @see RouterFunctions.nest
|
||||
*/
|
||||
fun RequestPredicate.nest(r: (CoRouterFunctionDsl.() -> Unit)) {
|
||||
builder.add(nest(this, CoRouterFunctionDsl(r).build()))
|
||||
builder.add(nest(this, CoRouterFunctionDsl(r).also { it.contextProvider = contextProvider }.build()))
|
||||
}
|
||||
|
||||
|
||||
@@ -628,9 +628,6 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
|
||||
* @since 6.1
|
||||
*/
|
||||
fun context(provider: suspend (ServerRequest) -> CoroutineContext) {
|
||||
if (this.contextProvider != null) {
|
||||
throw IllegalStateException("The Coroutine context provider should not be defined more than once")
|
||||
}
|
||||
this.contextProvider = provider
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user