in ktor-client, is there a way to add headers in a...
# ktor
x
in ktor-client, is there a way to add headers in a suspended context?
a
Yes.
Copy code
suspend fun main() {
    val client = HttpClient(CIO)

    <http://client.post|client.post>("<https://httpbin.org/post>") {
        delay(123)
        header("header", "value")
    }
}
x
Anyway to do this within `defaultConfig`s?
h
Considering I don’t know anything about your
loginRepository
implementation, it looks like you could perhaps wrap with
runBlocking
or
runCatching
in this case?
header(X-User-ID, runBlocking{(loginRepository.last().username)}
? Bear in mind that you should take into account the response time from
last()
and also make sure that the response is valid.
a
@xxfast unfortunately, no.
x
Made a feature request here
👍 1