Adv

6/02/2015

How to drop/abort HTTP connection from servlet?

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

Problem

  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

Facts

  • 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 http://stackoverflow.com/questions/30589597/how-to-drop-abort-http-connection-from-servlet
via IFTTT

沒有留言: