Ming Chun Or
08/26/2022, 3:54 AMonDwonload
hook but it seems didn’t help. The response.bodyAsChannel()
seems to be returning the whole response (buffered into memory?) before I can check and consume it. I want to cut the underlying HTTP call early if the response size is too large.Ming Chun Or
08/26/2022, 3:57 AMBodyProgress
plugin behind onDownload
only allow me to put listener on the download content size but did not allow me to cancel the Job
Aleksei Tirman [JB]
08/26/2022, 6:23 AMHttpRequestBuilder
manually to be able to refer to its executionContext
property which you can use to cancel a job. Here is an example:
suspend fun main(): Unit = runBlocking {
val client = HttpClient(Apache)
val builder = HttpRequestBuilder().apply {
url("<http://127.0.0.1:3333>")
onDownload { bytesSentTotal, contentLength ->
// executionContext.cancel() will work too
println("Received $bytesSentTotal bytes from $contentLength")
}
}
launch {
delay(200)
builder.executionContext.cancel()
}
client.get(builder)
}
Ming Chun Or
08/26/2022, 7:04 AMonDownload { bytesSentTotal, contentLength ->
executionContext.cancel()
}
It work perfectly! Thx ❤️