diff --git a/build.gradle.kts b/build.gradle.kts index 08e3e447..e6a2df0f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ dependencies { api(project(":darkbot-shared")) } -val apiVersion = "0.9.9" +val apiVersion = "0.9.11" allprojects { group = "eu.darkbot" diff --git a/util/src/main/java/eu/darkbot/util/http/Http.java b/util/src/main/java/eu/darkbot/util/http/Http.java index 008eb5f9..dba22a5b 100644 --- a/util/src/main/java/eu/darkbot/util/http/Http.java +++ b/util/src/main/java/eu/darkbot/util/http/Http.java @@ -12,6 +12,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.PushbackInputStream; import java.lang.reflect.Type; import java.net.HttpURLConnection; import java.net.URL; @@ -22,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import java.util.zip.GZIPInputStream; /** * Utility for HTTP connections. @@ -30,7 +32,8 @@ public class Http { private static final Gson GSON = new Gson(); - @Getter @Setter + @Getter + @Setter private static String defaultUserAgent = "BigpointClient/1.6.7"; protected final String baseUrl; @@ -291,7 +294,17 @@ public void closeInputStream() throws IOException { * @throws IOException of {@link Http#getConnection()} */ public InputStream getInputStream() throws IOException { - return getConnection().getInputStream(); + PushbackInputStream in = new PushbackInputStream(getConnection().getInputStream(), 2); + + byte[] header = new byte[2]; + int count = in.read(header); + if (count > 0) in.unread(header, 0, count); + + // Response may be gzip-compressed even without a Content-Encoding header + if (count == 2 && header[0] == (byte) 0x1f && header[1] == (byte) 0x8b) { + return new GZIPInputStream(in); + } + return in; } /**