-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Steffen,

On 5/29/16 2:08 PM, Steffen Heil (Mailinglisten) wrote:
> I am streaming a huge file from a servlet to the browser. It can
> easily be multiple gigabytes.
> 
> Currently the data is prepared on the server, stored in a file and
> then sent to the client with a "Content-Disposition: attachment"
> header, so the browser handles it as a download. After the transfer
> the file is immediately deleted.
> 
> This kind of works but has two big disadvantages: 1. The client has
> to wait a long time until the first byte is transferred. I am
> afraid I could run into browser (or generic client) timeouts. 2. I
> need a lot of storage on the server.
> 
> The data I have could easily be streamed directly to the client
> without storing it on the server at all. I would not know the
> precise size of the data In advance, but it could be transferred
> using "Transfer-Encoding: junked" so this would not be a problem.
> 
> My problem is that if anything goes wrong while creating the data I
> have no way to notify the client, as the response headers were
> already sent way before. So I am looking for a way to cancel the
> download from the server side and letting the client know that
> something went wrong. Simply stopping sending data is not enough,
> the client needs to know that the data is incomplete.
> 
> Probably the only way to do that would be to abruptly disconnect
> the http(s) connection without completing the download using a
> "0\r\n" end marker.
> 
> So my questions are: 1. How can I force tomcat to disconnect a
> client like that? 2. Does anyone here have tried anything like that
> before? What client side reactions did you notice?

I believe that, while the HTTP specification supports what you want to
do, neither servers nor clients support it. For example, you can use
"trailers" (headers end the end of the response) to tell the client
what happened, but I suspect that no client will actually read them or
act on them.

I don't think you really have an option, here, for transmitting a huge
file with graceful error-handling sometime in the middle of the
creation/transmission of the data.

You can always force a disconnect by simply closing the response
stream. Usually, the client will either tell the user that the
download failed (connection closed before response - or chunk of
response - completed), more likely just shows the user a blank page or
saves an incomplete file.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJXSzkyAAoJEBzwKT+lPKRYapoP/i9pIzvWTCVrfvUrYErQagyC
QIshcEX/Sqw3AlLLMiSuhSjykdn2pyRwu1XlwnVS+pRP0g0C5orj8QiQNGHJKg6m
dBCUe5rwBnGSvILFJMM7Nbq9i8mHyDhU3hWctjFbCXwL/i+q9pRZr66DkS9F1Hya
7QiDnqIvckZ3iYNn2JySWPVYTwDP718o17ypX+zmPOjRkYr66h/Xvtv8I5bpChgM
96zt9oGXPt8WDaWfrFMuZZlDsW2E+E6LVHQNEBWNepOuw5aLn6TgyWReWNysaeBY
NV5t1bzLEC1iYKquOqOZcsRBRHx7ArKtAv1RUYvsqSUpqiysgiWfYOYCFEyBCrET
mG9T/88GIiqW6+lZwdzxB6r2VPEgpbhQV0Ufwp55YWbHUPJPICYAVyA3lAlEGcG/
1ES9TduGcOF0CHYLAKYQ0dYBaGCGW1YjTHZ/C0bGMG7T4l7w0N/nQ6RrYuoMWsOt
CnE8FuqyVzHX1qT4FSCqyRSUYC7cNu8YccMpjmTcyjmC5KeZYbUTIMP3iAOVD0Dl
rZ2HOBdlMSwqJtnr6h3MUqF7mBqkKjhmt19mpEeXibsGpXCjULRNFXw7FIS3ZLyV
NK7EXJIfitldyF5nsIuXRQamPkBTht82zORBwYyjPrLgeEYLHYpOW3ewK8wvcBNB
f7r/Gh1KuHucNJwDrirw
=SqNN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to