Jason Toms
06/26/2024, 11:20 AMHttpResponse.content
is marked as internal, but it is exactly what I need since it is an unconsumed ByteReadChannel
that lets me use peekTo
...is there a good reason this is marked as internal and do you think I could use it anyway, or is there something else I could be using instead?Aleksei Tirman [JB]
06/26/2024, 1:56 PMByteReadChannel
to read from.Jason Toms
06/26/2024, 2:02 PMByteReadChannel
the body gets consumed. I have a plugin where I want to read the body to respond to certain types or errors, but the response should still get sent out of this plugin. So I am having a problem being able to see a response body both inside and outside of a pluginephemient
06/26/2024, 2:47 PMJason Toms
06/26/2024, 2:51 PMAleksei Tirman [JB]
06/26/2024, 7:16 PMByteReadChannel
into two channels to use one of them and return another. Here is an example:
val client = HttpClient(CIO)
val scope = CoroutineScope(coroutineContext)
client.responsePipeline.intercept(HttpResponsePipeline.Receive) { (type, body) ->
if (body !is ByteReadChannel) return@intercept
val (first, second) = body.split(scope)
println(first.toByteArray().size) // Consume first here
proceedWith(HttpResponseContainer(type, second))
}
client.prepareGet("<https://httpbin.org/get>").execute { // Stream the response body
println(it.bodyAsText())
}