ssr86
02/21/2021, 12:20 AMdave
02/21/2021, 10:04 AMRazvan
02/21/2021, 11:39 AMKotlin SSE client
directly instead of Java… I would have found directly this implementation…
https://github.com/biowink/oksseobject StreamSSE {
operator fun invoke(req: Request) {
val request = req
.replaceHeaders(
listOf(
"Accept-Encoding" to "",
"Accept" to "text/event-stream",
"Cache-Control" to "no-cache",
)
)
val noTimeoutClient = PreCannedOkHttpClients
.defaultOkHttpClient()
.newBuilder()
.readTimeout(Duration.ZERO)
.build()
OkHttp(client = noTimeoutClient, bodyMode = BodyMode.Stream).debug()(request).body.stream.bufferedReader().forEachLine {
println(it)
if (it.startsWith("End")) throw Exception("End")
}
}
}