Issue
I'm streaming response of unknown size to client from a servlet (really a Spring Boot controller but it shouldn't matter).
I force sending headers early by calling flush()
so that the client (browser) can properly show that the download is started.
What should I do if an error happens in the middle of the stream? Right now client simply gets part of the file and has no idea it's bad.
According to What to do with errors when streaming the body of an Http request I should to TCP RST on Socket or write some garbage that is not a valid chunked encoded data.
Unfortunately I have not found a way of accessing underlying socket nor can I write malformed response - ServletResponse#getOutputStream
does chunking internally and I couldn't find a way of bypassing that either.
Solution
This was fixed in https://github.com/apache/tomcat/commit/fa0f2567aae91a13137094ebcdb74d72b8222f3b
And is available since Tomcat to 10.1.0.
Answered By - Marcin Wisnicki
Answer Checked By - Robin (JavaFixing Admin)