diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ApiHandler.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ApiHandler.java index 4c03ecf2b8..088161a05b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ApiHandler.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/modpacks/api/ApiHandler.java @@ -1,5 +1,7 @@ package net.kdt.pojavlaunch.modloaders.modpacks.api; +import static net.kdt.pojavlaunch.utils.DownloadUtils.USER_AGENT; + import android.util.ArrayMap; import android.util.Log; @@ -22,16 +24,15 @@ @SuppressWarnings("unused") public class ApiHandler { public final String baseUrl; - public final Map additionalHeaders; + public final Map additionalHeaders = new ArrayMap<>(); public ApiHandler(String url) { baseUrl = url; - additionalHeaders = null; + additionalHeaders.put("User-Agent", USER_AGENT); } public ApiHandler(String url, String apiKey) { - baseUrl = url; - additionalHeaders = new ArrayMap<>(); + this(url); additionalHeaders.put("x-api-key", apiKey); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/DownloadUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/DownloadUtils.java index b4df71409a..67a474f130 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/DownloadUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/DownloadUtils.java @@ -14,7 +14,8 @@ @SuppressWarnings("IOStreamConstructor") public class DownloadUtils { - public static final String USER_AGENT = Tools.APP_NAME; + //Standardize the User-Agent format to "Launcher Name/Launcher Version" to facilitate data collection by resource platforms. + public static final String USER_AGENT = Tools.APP_NAME + "/" + BuildConfig.VERSION_NAME; public static void download(String url, OutputStream os) throws IOException { download(new URL(url), os); @@ -67,6 +68,7 @@ public static void downloadFileMonitored(String urlInput, File outputFile, @Null FileUtils.ensureParentDirectory(outputFile); HttpURLConnection conn = (HttpURLConnection) new URL(urlInput).openConnection(); + conn.setRequestProperty("User-Agent", USER_AGENT); InputStream readStr = conn.getInputStream(); try (FileOutputStream fos = new FileOutputStream(outputFile)) { int current;