From a1fdc4cc39b2219c04f0ab2199acf44b804505ac Mon Sep 17 00:00:00 2001 From: dima_dencep Date: Sat, 24 Sep 2022 00:22:23 +0700 Subject: [PATCH] small fix user agent --- .../src/main/java/pro/gravit/launcher/HTTPRequest.java | 3 ++- .../src/main/java/pro/gravit/utils/helper/IOHelper.java | 4 +++- .../src/main/java11/pro/gravit/launcher/HTTPRequest.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java b/LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java index d33adae1..7a688ded 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java @@ -2,6 +2,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import java.io.IOException; @@ -27,7 +28,7 @@ public static JsonElement jsonRequest(JsonElement request, String method, URL ur if (request != null) connection.setDoOutput(true); connection.setRequestMethod(method); if (request != null) connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); - if (request != null) connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"); + if (request != null) connection.setRequestProperty("User-Agent", IOHelper.USER_AGENT); connection.setRequestProperty("Accept", "application/json"); if (TIMEOUT > 0) connection.setConnectTimeout(TIMEOUT); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index ba16d237..e74afed9 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -1,5 +1,7 @@ package pro.gravit.utils.helper; +import pro.gravit.utils.Version; + import javax.imageio.ImageIO; import javax.imageio.ImageReader; import java.awt.image.BufferedImage; @@ -43,7 +45,7 @@ public final class IOHelper { public static final Path JVM_DIR = Paths.get(System.getProperty("java.home")); public static final Path HOME_DIR = Paths.get(System.getProperty("user.home")); public static final Path WORKING_DIR = Paths.get(System.getProperty("user.dir")); - public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); + public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", String.format("GravitLauncher/%s", Version.getVersion())); // Open options - as arrays private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ}; private static final OpenOption[] WRITE_OPTIONS = {StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING}; diff --git a/LauncherCore/src/main/java11/pro/gravit/launcher/HTTPRequest.java b/LauncherCore/src/main/java11/pro/gravit/launcher/HTTPRequest.java index eef69ae4..95a3350e 100644 --- a/LauncherCore/src/main/java11/pro/gravit/launcher/HTTPRequest.java +++ b/LauncherCore/src/main/java11/pro/gravit/launcher/HTTPRequest.java @@ -39,7 +39,7 @@ public static JsonElement jsonRequest(JsonElement request, String method, URL ur .uri(url.toURI()) .header("Content-Type", "application/json; charset=UTF-8") .header("Accept", "application/json") - .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36") + .header("User-Agent", IOHelper.USER_AGENT) .timeout(Duration.ofMillis(TIMEOUT)) .build(); HttpResponse response = client.send(request1, HttpResponse.BodyHandlers.ofInputStream());