1

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.

Marcin Wisnicki
  • 4,511
  • 4
  • 35
  • 57
  • 1
    Note this seems to be a Spring Boot bug / Tomcat limitation: https://github.com/spring-projects/spring-boot/issues/27624. Plain Tomcat works and so does Spring Boot with Jetty. Still it would be nice to have some sort of workable workaround... – Marcin Wisnicki Aug 11 '21 at 01:48

1 Answers1

0

This was fixed in https://github.com/apache/tomcat/commit/fa0f2567aae91a13137094ebcdb74d72b8222f3b

And is available since Tomcat to 10.1.0.

Marcin Wisnicki
  • 4,511
  • 4
  • 35
  • 57