Actually handle gzip encoded connections when downloading.

dev/0.11
modmuss50 2021-07-16 22:48:50 +01:00
parent 777f30913b
commit 34b771f744
2 changed files with 18 additions and 2 deletions

View File

@ -26,9 +26,11 @@ package net.fabricmc.loom.util;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import com.google.common.io.Files; import com.google.common.io.Files;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -110,7 +112,13 @@ public class DownloadUtil {
} }
try { // Try download to the output try { // Try download to the output
FileUtils.copyInputStreamToFile(connection.getInputStream(), to); InputStream inputStream = connection.getInputStream();
if ("gzip".equals(connection.getContentEncoding())) {
inputStream = new GZIPInputStream(inputStream);
}
FileUtils.copyInputStreamToFile(inputStream, to);
} catch (IOException e) { } catch (IOException e) {
delete(to); // Probably isn't good if it fails to copy/save delete(to); // Probably isn't good if it fails to copy/save
throw e; throw e;

View File

@ -27,9 +27,11 @@ package net.fabricmc.loom.util;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -78,7 +80,13 @@ public class HashedDownloadUtil {
} }
try { // Try download to the output try { // Try download to the output
FileUtils.copyInputStreamToFile(connection.getInputStream(), to); InputStream inputStream = connection.getInputStream();
if ("gzip".equals(connection.getContentEncoding())) {
inputStream = new GZIPInputStream(inputStream);
}
FileUtils.copyInputStreamToFile(inputStream, to);
} catch (IOException e) { } catch (IOException e) {
delete(to); // Probably isn't good if it fails to copy/save delete(to); // Probably isn't good if it fails to copy/save
throw e; throw e;