How to drop/abort HTTP connection from servlet?

I'd like to force connection abort in servlet, without using HTTP header.


  1. I have a servlet that generate a file download, which pipe some bytes to OutputStream
  2. The browser read the header, with UNKNOWN-FILE-SIZE
  3. The browser downloading byte streams.
  4. Servlet could like to abort the download in the middle.
  5. Let the browser abort and delete the downloaded file, and mark it as failed


  • The header is already sent.
  • The file-size is unknown until complete, cannot use Content-Length:
  • There is no .abort() or .disconnect() in HttpServlet{Request,Response}
  • The servlet has to be generic, without hacking servlet container specific API for Socket stealing
  • The contains and size are dynamic, which could be heavy for generate file(or make sure everything are in RAM) before download

from User Dennis Cheung - Stack Overflow