From b12f18fdbc60f141657ecfbd18590724666b593d Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sat, 22 Apr 2023 13:37:28 +0200 Subject: Make ApiUtil accept gzip encoding (#677) --- .../java/io/github/moulberry/notenoughupdates/util/ApiUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index 3cb17772..0cda91fd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -70,12 +70,14 @@ public class ApiUtil { .thenComparing(NameValuePair::getValue); private static final ExecutorService executorService = Executors.newFixedThreadPool(3); + private static String getUserAgent() { if (NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent != null) { return NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent; } return "NotEnoughUpdates/" + NotEnoughUpdates.VERSION; } + private static SSLContext ctx; private final Map> updateTasks = new HashMap<>(); private static boolean notifiedOfInvalidApiKey; @@ -209,6 +211,9 @@ public class ApiUtil { if (this.postContentType != null) { conn.setRequestProperty("Content-Type", this.postContentType); } + if (!shouldGunzip) { + conn.setRequestProperty("Accept-Encoding", "gzip"); // Tell the server we can accept gzip + } if (this.postData != null) { conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); @@ -221,7 +226,7 @@ public class ApiUtil { inputStream = conn.getInputStream(); - if (shouldGunzip) { + if (shouldGunzip || "gzip".equals(conn.getContentEncoding())) { inputStream = new GZIPInputStream(inputStream); } -- cgit