Support multiple CoWebFilter changing the context
This commit ensures CoWebFilter merges the exchange CoroutineContext with the filter one if needed. Closes gh-31792
This commit is contained in:
@@ -22,6 +22,7 @@ import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.reactor.awaitSingleOrNull
|
||||
import kotlinx.coroutines.reactor.mono
|
||||
import reactor.core.publisher.Mono
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* Kotlin-specific implementation of the [WebFilter] interface that allows for
|
||||
@@ -34,7 +35,8 @@ import reactor.core.publisher.Mono
|
||||
abstract class CoWebFilter : WebFilter {
|
||||
|
||||
final override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
|
||||
return mono(Dispatchers.Unconfined) {
|
||||
val context = exchange.attributes[COROUTINE_CONTEXT_ATTRIBUTE] as CoroutineContext?
|
||||
return mono(context ?: Dispatchers.Unconfined) {
|
||||
filter(exchange, object : CoWebFilterChain {
|
||||
override suspend fun filter(exchange: ServerWebExchange) {
|
||||
exchange.attributes[COROUTINE_CONTEXT_ATTRIBUTE] = currentCoroutineContext().minusKey(Job.Key)
|
||||
|
||||
Reference in New Issue
Block a user