Hi, why default request builder lambda is not `sus...
# ktor
b
Hi, why default request builder lambda is not
suspend
in the Default Request plugin? I want to add some header to the request from a local storage, and the query to that storage is based on coroutines. Thought Ktor as the superior client would handle that easily. To my suprise this won't compile because the builder is missing the
suspend
modifier. Why is that?
Copy code
install(DefaultRequest) {
    header("some key", someRepo.getValue())
}
Where
someRepo.getValue()
is suspend function. Based on implementation of Default Request plugin I've managed to create such a bypass for that when building the HttpClient:
Copy code
.apply {
    requestPipeline.intercept(HttpRequestPipeline.Before) {
        header("some key", someRepo.getValue())
    }
}
for now I've created a ticket for that, and maybe will even try to contribute it myself https://youtrack.jetbrains.com/issue/KTOR-8775/Make-Default-Request-builder-suspend
s
Is the workaround for this to just use the HttpSend plugin perhaps? https://ktor.io/docs/client-http-send.html So doing smth like:
Copy code
HttpClient().config
  defaultRequest {
    header(... add non-suspend headers here)
  }
  install(HttpSend)
}.apply {
  plugin(HttpSend).intercept { request ->
    execute(request.apply { header(... add suspend headers here) })
  }
}
I asked here too https://kotlinlang.slack.com/archives/C0A974TJ9/p1765814943413549 since nobody will really read this half a year old threat at this point.