I have an application with WebFlux/Coroutines and ...
# spring
r
I have an application with WebFlux/Coroutines and I need to get and persist all headers from current request (for further audit). Is there a way to put them in CoroutineContext via WebFlux Filter? Any ideas?
d
with spring boot 2.2.x you got nice interop between reactor and coroutine context
if you populate subscriber context you can access it later on as
coroutineContext[ReactorContext]?.context
if you find some better way please let me know 🙂
r
thanks @Dariusz Kuc, it works 🙂
Copy code
@Bean
fun webFilter() = WebFilter { exchange, chain ->
    chain.filter(exchange).subscriberContext { context ->
        context.put(METADATA, exchange.request.headers.toSingleValueMap())
    }
}