diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java index 5414a7c405..c15b166678 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java @@ -142,7 +142,7 @@ public String getString() throws IOException { return getStringWithRetry(() -> { HttpURLConnection con = createConnection(); con = resolveConnection(con); - return IOUtils.readFullyAsString(con.getInputStream()); + return IOUtils.readFullyAsString("gzip".equals(con.getContentEncoding()) ? IOUtils.wrapFromGZip(con.getInputStream()) : con.getInputStream()); }, retryTimes); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/IOUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/IOUtils.java index 3b926719a0..76d07783b6 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/IOUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/IOUtils.java @@ -18,6 +18,7 @@ package org.jackhuang.hmcl.util.io; import java.io.*; +import java.util.zip.GZIPInputStream; /** * This utility class consists of some util methods operating on InputStream/OutputStream. @@ -79,4 +80,8 @@ public static void copyTo(InputStream src, OutputStream dest, byte[] buf) throws dest.write(buf, 0, len); } } + + public static InputStream wrapFromGZip(InputStream inputStream) throws IOException { + return new GZIPInputStream(inputStream); + } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java index f16ba9dedf..9db3fbc7c0 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java @@ -209,13 +209,13 @@ public static String doPost(URL url, String post, String contentType) throws IOE public static String readData(HttpURLConnection con) throws IOException { try { try (InputStream stdout = con.getInputStream()) { - return IOUtils.readFullyAsString(stdout); + return IOUtils.readFullyAsString("gzip".equals(con.getContentEncoding()) ? IOUtils.wrapFromGZip(stdout) : stdout); } } catch (IOException e) { try (InputStream stderr = con.getErrorStream()) { if (stderr == null) throw e; - return IOUtils.readFullyAsString(stderr); + return IOUtils.readFullyAsString("gzip".equals(con.getContentEncoding()) ? IOUtils.wrapFromGZip(stderr) : stderr); } } }