I'm using the StreamingResponse and AsyncStream classes, which seem to be just the right tool for this job.
This is my implementation:
get("/foobar") { request: Request =>
val resultStream: MyInputStream = ...
val reader: Reader = com.twitter.io.Reader.fromStream(resultStream)
val asyncStream = AsyncStream.fromReader(reader, RESPONSE_CHUNK_SIZE)
StreamingResponse(Predef.identity[Buf], headers = headers)(asyncStream)
}
My problem is that I must close the input stream in order to release the resources used to generate the stream. However, the close method of the inputstream is never called by Finatra, even after the client finishes reading the response and exits.
Is there a way of receiving a notification when Finatra finishes streaming the response to the client? I can implement a custom inputstream which automatically closes itself when the last byte is read, but this seems very hacky and does not handle the cases where the response is interrupted and the inputstream is not fully read.
I'm using Finatra 2.3.0 (cannot upgrade because the dependency on Netty 4.1 makes it incompatible with Spark, which I am also using in this program).
Thank you in advance
Nuno
--
You received this message because you are subscribed to the Google Groups "finatra-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to finatra-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "finatra-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/finatra-users/0skjNCw1tec/unsubscribe.
To unsubscribe from this group and all its topics, send an email to finatra-users+unsubscribe@googlegroups.com.