Am 16.08.2013 11:34, schrieb Sönke Ludwig:

On Mon, 12 Aug 2013 20:42:15 GMT, nazriel wrote:

On Mon, 12 Aug 2013 17:45:55 GMT, Sönke Ludwig wrote:

On Sun, 11 Aug 2013 15:12:48 GMT, nazriel wrote:

(...)

 if (last_read < BUFF_SIZE)
 {
     break;
 }

(...)

This check should be removed, as it may very well trigger in the middle of the transfer. It's the number of bytes in the receive buffer of the socket and that may be just a few bytes for example if the client reads faster than the origin server writes.

You can also replace the whole while loop with the following, which will basically do exactly the same thing:

 res.bodyWriter.write(r.bodyReader);


I could swear I used it and I had issues with it.
No idea what happened back then but now it just works hah.

Everything seems to work now.
The only issue I have got is the fact, that when I set loglevel to trace, and client disconnects (for example stops download), app seems to still download file from remote server (I maybe wrong here. Got bunch of:

(...)

Shouldn't it stop downloading remote file after user disconnects in my scenario?

I think this may happen because the body writer stream is a ChunkedOutputStream in this case, which will happily buffer without checking the underlying connection. I'll add a manual check and also make the default chunk size limited to avoid using up all memory in case of large files.

Hmm actually this is not true in this particular case.
ChunkedOutputStream.write is overloaded for the stream case and does
the right thing. I would normally expect it to exit with an exception as
soon as the client connection gets terminated - I'll look into it when I
get the chance.