From 419aebf5220c83f12e01afed389362465309e8d3 Mon Sep 17 00:00:00 2001 From: TeYroXOfficial <57874535+TeYroXOfficial@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:38:42 +0200 Subject: [PATCH 1/4] Handle gzip-compressed responses Http.getInputStream() DarkOrbit started sending gzip-compressed responses. This PR checks whether the response is gzip-compressed and decompresses it if so; otherwise the stream is passed through unchanged. --- util/src/main/java/eu/darkbot/util/http/Http.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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..fbe4bb72 100644 --- a/util/src/main/java/eu/darkbot/util/http/Http.java +++ b/util/src/main/java/eu/darkbot/util/http/Http.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.Setter; +import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -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. @@ -291,7 +293,13 @@ public void closeInputStream() throws IOException { * @throws IOException of {@link Http#getConnection()} */ public InputStream getInputStream() throws IOException { - return getConnection().getInputStream(); + InputStream in = new BufferedInputStream(getConnection().getInputStream()); + in.mark(2); + int b1 = in.read(), b2 = in.read(); + in.reset(); + // Response may be gzip-compressed even without a Content-Encoding header + if (b1 == 0x1f && b2 == 0x8b) return new GZIPInputStream(in); + return in; } /** From a5a34b81da24dfa9f1d6c362c3f30eaaece8212e Mon Sep 17 00:00:00 2001 From: TeYroXOfficial <57874535+TeYroXOfficial@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:38:47 +0200 Subject: [PATCH 2/4] Update build.gradle.kts --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 08e3e447..a317486b 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.10" allprojects { group = "eu.darkbot" From 0fd80f44425e2cb409310cd038f67a8efd897436 Mon Sep 17 00:00:00 2001 From: TeYroXOfficial <57874535+TeYroXOfficial@users.noreply.github.com> Date: Wed, 16 Sep 2026 17:16:51 +0200 Subject: [PATCH 3/4] Update util/src/main/java/eu/darkbot/util/http/Http.java Yes, these changes work as well as expected Co-authored-by: Pablo Herrera --- util/src/main/java/eu/darkbot/util/http/Http.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 fbe4bb72..7e7f0628 100644 --- a/util/src/main/java/eu/darkbot/util/http/Http.java +++ b/util/src/main/java/eu/darkbot/util/http/Http.java @@ -293,12 +293,16 @@ public void closeInputStream() throws IOException { * @throws IOException of {@link Http#getConnection()} */ public InputStream getInputStream() throws IOException { - InputStream in = new BufferedInputStream(getConnection().getInputStream()); - in.mark(2); - int b1 = in.read(), b2 = in.read(); - in.reset(); + 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 (b1 == 0x1f && b2 == 0x8b) return new GZIPInputStream(in); + if (count == 2 && header[0] == 0x1f && header[1] == 0x8b) { + return new GZIPInputStream(in); + } return in; } From 248c734bf223c844430473c65ba0243bd047f917 Mon Sep 17 00:00:00 2001 From: TeYroXOfficial <57874535+TeYroXOfficial@users.noreply.github.com> Date: Wed, 16 Sep 2026 17:24:06 +0200 Subject: [PATCH 4/4] Fix gzip detection: read full header and compare unsigned bytes Co-Authored-By: Claude Opus 5 --- build.gradle.kts | 2 +- util/src/main/java/eu/darkbot/util/http/Http.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a317486b..08e3e447 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ dependencies { api(project(":darkbot-shared")) } -val apiVersion = "0.9.10" +val apiVersion = "0.9.9" 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 7e7f0628..36e5871a 100644 --- a/util/src/main/java/eu/darkbot/util/http/Http.java +++ b/util/src/main/java/eu/darkbot/util/http/Http.java @@ -6,13 +6,13 @@ import lombok.Getter; import lombok.Setter; -import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; 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; @@ -296,11 +296,16 @@ public InputStream getInputStream() throws IOException { PushbackInputStream in = new PushbackInputStream(getConnection().getInputStream(), 2); byte[] header = new byte[2]; - int count = in.read(header); + int count = 0; + while (count < header.length) { + int read = in.read(header, count, header.length - count); + if (read == -1) break; + count += read; + } if (count > 0) in.unread(header, 0, count); // Response may be gzip-compressed even without a Content-Encoding header - if (count == 2 && header[0] == 0x1f && header[1] == 0x8b) { + if (count == 2 && (header[0] & 0xff) == 0x1f && (header[1] & 0xff) == 0x8b) { return new GZIPInputStream(in); } return in;