Skip to content

Inherit parent context in coRouter DSL #31831

Closed
@sdeleuze

Description

@sdeleuze

As reported in this Stackoverflow question, the CoroutineContext defined in the parent router is lost in nested routers, which is a surprising behavior. For example with this router, a request on / will have the context set as expected, but not a request on /nested/.

coRouter {
    context { CoroutineName("Custom context") }
    GET("/") {
        ok().bodyValueAndAwait(currentCoroutineContext().toString())
    }
    "/nested".nest {
        GET("/") {
            ok().bodyValueAndAwait(currentCoroutineContext().toString())
        }
    }
}

This issue is about inheriting the CoroutineContext in such use case to provide a more predictable behavior, while still allowing an override in nested routers.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)theme: kotlinAn issue related to Kotlin supporttype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions