From 58bca1826fd1612db57862e40f00419a30d9ef48 Mon Sep 17 00:00:00 2001 From: NotCoded <66999075+not-coded@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:36:52 +0100 Subject: [PATCH] tweaks to http in utils --- src/main/java/com/nexia/installer/util/Utils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/nexia/installer/util/Utils.java b/src/main/java/com/nexia/installer/util/Utils.java index 36aed3c..b828cdb 100644 --- a/src/main/java/com/nexia/installer/util/Utils.java +++ b/src/main/java/com/nexia/installer/util/Utils.java @@ -22,6 +22,8 @@ public class Utils { public static final DateFormat ISO_8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + public static String userAgent = "Mozilla/5.0 (compatible; combat-test-installer; +https://github.com/nexia-cts/combat-test-installer)"; + public static void extractZip(Path file, Path path) throws IOException { ZipInputStream zipIn = new ZipInputStream(Files.newInputStream(Paths.get(file.toString()))); ZipEntry entry = zipIn.getNextEntry(); @@ -56,7 +58,7 @@ public static void writeToFile(Path path, String string) throws IOException { Files.write(path, string.getBytes(StandardCharsets.UTF_8)); } - public static void downloadFile(URL url, Path path) throws IOException { + public static void downloadFile(URL url, Path path) { try (InputStream in = openUrl(url)) { Files.createDirectories(path.getParent()); Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING); @@ -67,7 +69,8 @@ public static void downloadFile(URL url, Path path) throws IOException { t.addSuppressed(t2); } - throw t; + InstallerUtils.showError(t.getMessage()); + t.printStackTrace(); } } @@ -76,6 +79,7 @@ public static void downloadFile(URL url, Path path) throws IOException { private static InputStream openUrl(URL url) throws IOException { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestProperty("User-Agent", userAgent); conn.setConnectTimeout(HTTP_TIMEOUT_MS); conn.setReadTimeout(HTTP_TIMEOUT_MS); conn.connect();