From 4da80dfae0260a514dfaeef06f80b1371e96e280 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Tue, 9 Mar 2021 20:14:16 +0000 Subject: [PATCH] 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. --- .../src/main/java/com/skcraft/launcher/util/HttpRequest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java b/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java index bef8ea9..0823669 100644 --- a/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java +++ b/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java @@ -328,6 +328,11 @@ public class HttpRequest implements Closeable, ProgressObservable { readBytes += len; checkInterrupted(); } + + if (contentLength >= 0 && contentLength != readBytes) { + throw new IOException(String.format("Connection closed with %d bytes transferred, expected %d", + readBytes, contentLength)); + } } finally { close(); }