[FIX] UserAgent в ListDownloader.

This commit is contained in:
Zaxar163 2019-10-09 15:32:46 +02:00
parent 3d7c2f31ef
commit cb91f83ec2
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
2 changed files with 3 additions and 2 deletions

View file

@ -62,7 +62,7 @@ public DownloadTask(String apply, long size) {
} }
public void download(String base, List<DownloadTask> applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { public void download(String base, List<DownloadTask> 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()) .setRedirectStrategy(new LaxRedirectStrategy())
.build()) { .build()) {
applies.sort((a,b) -> Long.compare(a.size, b.size)); applies.sort((a,b) -> Long.compare(a.size, b.size));

View file

@ -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 CROSS_SEPARATOR_PATTERN = Pattern.compile(CROSS_SEPARATOR, Pattern.LITERAL);
private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_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 @LauncherAPI
public static void close(AutoCloseable closeable) { public static void close(AutoCloseable closeable) {
@ -346,7 +347,7 @@ public static URLConnection newConnection(URL url) throws IOException {
if (connection instanceof HttpURLConnection) { if (connection instanceof HttpURLConnection) {
connection.setReadTimeout(HTTP_TIMEOUT); connection.setReadTimeout(HTTP_TIMEOUT);
connection.setConnectTimeout(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 } else
connection.setUseCaches(false); connection.setUseCaches(false);
connection.setDoInput(true); connection.setDoInput(true);