From cb91f83ec258c7d6891e4cfd62a38294b48dfddc Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 9 Oct 2019 15:32:46 +0200 Subject: [PATCH] =?UTF-8?q?[FIX]=20UserAgent=20=D0=B2=20ListDownloader.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/downloader/ListDownloader.java | 2 +- .../src/main/java/pro/gravit/utils/helper/IOHelper.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index bb7c40d7..32cfa9d4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -62,7 +62,7 @@ public DownloadTask(String apply, long size) { } public void download(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { - try (CloseableHttpClient httpclient = HttpClients.custom() + try (CloseableHttpClient httpclient = HttpClients.custom().setUserAgent(IOHelper.USER_AGENT) .setRedirectStrategy(new LaxRedirectStrategy()) .build()) { applies.sort((a,b) -> Long.compare(a.size, b.size)); 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 1d602582..e8929abe 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -168,6 +168,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce private static final Pattern CROSS_SEPARATOR_PATTERN = Pattern.compile(CROSS_SEPARATOR, Pattern.LITERAL); private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL); + public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); @LauncherAPI public static void close(AutoCloseable closeable) { @@ -346,7 +347,7 @@ public static URLConnection newConnection(URL url) throws IOException { if (connection instanceof HttpURLConnection) { connection.setReadTimeout(HTTP_TIMEOUT); connection.setConnectTimeout(HTTP_TIMEOUT); - connection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); // Fix for stupid servers + connection.addRequestProperty("User-Agent", USER_AGENT); // Fix for stupid servers } else connection.setUseCaches(false); connection.setDoInput(true);