diff options
author | Roman / Linnea Gräf <roman.graef@gmail.com> | 2023-02-07 06:25:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 16:25:16 +1100 |
commit | 9ac80842dd3e280bd1468c7261d30c21968b0da1 (patch) | |
tree | 2bd972c0c622d91c6a83bbe27aa5c6afcb53f74d /src | |
parent | b9f9917306b3b522ef83f22faef30977ac73fd52 (diff) | |
download | NotEnoughUpdates-9ac80842dd3e280bd1468c7261d30c21968b0da1.tar.gz NotEnoughUpdates-9ac80842dd3e280bd1468c7261d30c21968b0da1.tar.bz2 NotEnoughUpdates-9ac80842dd3e280bd1468c7261d30c21968b0da1.zip |
ApiUtil: Add developer only user agent override (#590)
Co-authored-by: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>
Diffstat (limited to 'src')
3 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index 0d882358..35474ff3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -254,5 +254,10 @@ public class DevTestCommand extends ClientCommandBase { MiscUtils.copyToClipboard(builder.toString()); Utils.addChatMessage("§e[NEU] Copied tablist to clipboard!"); } + if (args.length >= 1 && args[0].equalsIgnoreCase("useragent")) { + String newUserAgent = args.length == 1 ? null : String.join(" ", Arrays.copyOfRange(args, 1, args.length)); + Utils.addChatMessage("§e[NEU] Changed user agent override to: " + newUserAgent); + NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = newUserAgent; + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 371d657e..a289ca51 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -438,6 +438,8 @@ public class NEUConfig extends Config { @Expose public int compareMode = 0; @Expose + public String customUserAgent = null; + @Expose public int sortMode = 0; @Expose public ArrayList<Boolean> compareAscending = Lists.newArrayList(true, true, true); 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 0c590bab..023be060 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -61,7 +61,12 @@ import java.util.zip.GZIPInputStream; public class ApiUtil { private static final Gson gson = new Gson(); private static final ExecutorService executorService = Executors.newFixedThreadPool(3); - private static final String USER_AGENT = "NotEnoughUpdates/" + NotEnoughUpdates.VERSION; + 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<String, CompletableFuture<Void>> updateTasks = new HashMap<>(); @@ -170,7 +175,7 @@ public class ApiUtil { } conn.setConnectTimeout(10000); conn.setReadTimeout(10000); - conn.setRequestProperty("User-Agent", USER_AGENT); + conn.setRequestProperty("User-Agent", getUserAgent()); if (this.postContentType != null) { conn.setRequestProperty("Content-Type", this.postContentType); } |