1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-24 12:16:28 +01:00

Throw an error if HTTP file transfers are cleanly closed early

It seems that some HTTP servers can silently close the connection before
the file has finished transferring. Since we count the transferred bytes
anyway, throw an exception if we didn't get the number of bytes the
server previously told us to expect.
This commit is contained in:
Henry Le Grys 2021-03-09 20:14:16 +00:00
parent 8a2b566b18
commit 4da80dfae0

View File

@ -328,6 +328,11 @@ public class HttpRequest implements Closeable, ProgressObservable {
readBytes += len; readBytes += len;
checkInterrupted(); checkInterrupted();
} }
if (contentLength >= 0 && contentLength != readBytes) {
throw new IOException(String.format("Connection closed with %d bytes transferred, expected %d",
readBytes, contentLength));
}
} finally { } finally {
close(); close();
} }