How can you handle large responses in a chunked/st...
# http4k
m
How can you handle large responses in a chunked/streaming fashion? You can return a
StreamBody
with an
InputStream
. That works fine if you are serving a file, but what if you are generating a large response chunk by chunk? And don't want to buffer the whole response before start serving the first part.
m
Your
InputStream
can be any kind of
InputStream
, including one that computes its bytes on demand
It's just an abstraction, the implementation and buffering is up to you
m
Yes, I guess so. However, in this case it would be more convenient to be able to push data to the response, rather than having the response pulling data from me.
m
TCP has Flow control, you can't push faster than the client can accept
If you want to push, you have to buffer
m
Yeah, I guess some kind of reactive stream with back-pressure would be nice here.