Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
api(project(":darkbot-shared"))
}

val apiVersion = "0.9.9"
val apiVersion = "0.9.11"

allprojects {
group = "eu.darkbot"
Expand Down
17 changes: 15 additions & 2 deletions util/src/main/java/eu/darkbot/util/http/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Loading