Remove proxy from FileDownloadTask/GetTask/NetworkUtils

This commit is contained in:
yushijinhun 2018-07-18 16:27:07 +08:00
parent 2f6c7e1ce2
commit 06806bd383
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
14 changed files with 31 additions and 68 deletions

View File

@ -154,7 +154,7 @@ public final class AccountHelper {
File file = getSkinFile(profile.getId());
if (!refresh && file.exists())
return;
new FileDownloadTask(NetworkUtils.toURL(url), file, proxy).run();
new FileDownloadTask(NetworkUtils.toURL(url), file).run();
}
private static void downloadSkin(YggdrasilAccount account, boolean refresh, Proxy proxy) throws Exception {
@ -167,7 +167,7 @@ public final class AccountHelper {
File file = getSkinFile(account.getUUID());
if (!refresh && file.exists())
return;
new FileDownloadTask(NetworkUtils.toURL(url), file, proxy).run();
new FileDownloadTask(NetworkUtils.toURL(url), file).run();
}
public static Image scale(String url, double scaleRatio) {

View File

@ -71,7 +71,6 @@ public class HMCLGameDownloadTask extends Task {
dependencies.add(new FileDownloadTask(
NetworkUtils.toURL(profile.getDependency().getDownloadProvider().injectURL(version.getDownloadInfo().getUrl())),
cache,
profile.getDependency().getProxy(),
new IntegrityCheck("SHA-1", version.getDownloadInfo().getSha1())
).then(Task.of(v -> FileUtils.copyFile(cache, jar))));
}

View File

@ -185,7 +185,7 @@ public class AppDataUpgrader extends IUpgrader {
@Override
public Collection<Task> getDependents() {
return Collections.singleton(new FileDownloadTask(downloadLink, tempFile, Proxy.NO_PROXY, new IntegrityCheck("SHA-1", hash)));
return Collections.singleton(new FileDownloadTask(downloadLink, tempFile, new IntegrityCheck("SHA-1", hash)));
}
@Override
@ -235,7 +235,7 @@ public class AppDataUpgrader extends IUpgrader {
@Override
public Collection<Task> getDependents() {
return Collections.singleton(new FileDownloadTask(downloadLink, tempFile, Proxy.NO_PROXY, new IntegrityCheck("SHA-1", hash)));
return Collections.singleton(new FileDownloadTask(downloadLink, tempFile, new IntegrityCheck("SHA-1", hash)));
}
@Override

View File

@ -20,7 +20,6 @@ package org.jackhuang.hmcl.auth.authlibinjector;
import static org.jackhuang.hmcl.util.Logging.LOG;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
@ -81,7 +80,7 @@ public class AuthlibInjectorDownloader {
}
try {
new FileDownloadTask(new URL(downloadProvider.get().injectURL(latest.downloadUrl)), artifactLocation.toFile(), Proxy.NO_PROXY,
new FileDownloadTask(new URL(downloadProvider.get().injectURL(latest.downloadUrl)), artifactLocation.toFile(),
Optional.ofNullable(latest.checksums.get("sha256"))
.map(checksum -> new IntegrityCheck("SHA-256", checksum))
.orElse(null))

View File

@ -107,7 +107,7 @@ public final class GameAssetDownloadTask extends Task {
flag = !file.exists();
}
if (flag) {
FileDownloadTask task = new FileDownloadTask(NetworkUtils.toURL(url), file, dependencyManager.getProxy(), new IntegrityCheck("SHA-1", assetObject.getHash()));
FileDownloadTask task = new FileDownloadTask(NetworkUtils.toURL(url), file, new IntegrityCheck("SHA-1", assetObject.getHash()));
task.setName(assetObject.getHash());
dependencies.add(task);
}

View File

@ -67,7 +67,7 @@ public final class GameAssetIndexDownloadTask extends Task {
File assetIndexFile = dependencyManager.getGameRepository().getIndexFile(version.getId(), assetIndexInfo.getId());
dependencies.add(new FileDownloadTask(
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(assetIndexInfo.getUrl())),
assetIndexFile, dependencyManager.getProxy()
assetIndexFile
));
}

View File

@ -56,7 +56,6 @@ public final class GameDownloadTask extends Task {
dependencies.add(new FileDownloadTask(
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(version.getDownloadInfo().getUrl())),
jar,
dependencyManager.getProxy(),
new IntegrityCheck("SHA-1", version.getDownloadInfo().getSha1())
));
}

View File

@ -66,7 +66,7 @@ public final class GameLoggingDownloadTask extends Task {
LoggingInfo logging = version.getLogging().get(DownloadType.CLIENT);
File file = dependencyManager.getGameRepository().getLoggingObject(version.getId(), version.getAssetIndex().getId(), logging);
if (!file.exists())
dependencies.add(new FileDownloadTask(NetworkUtils.toURL(logging.getFile().getUrl()), file, dependencyManager.getProxy()));
dependencies.add(new FileDownloadTask(NetworkUtils.toURL(logging.getFile().getUrl()), file));
}
}

View File

@ -43,13 +43,13 @@ public final class LibraryDownloadTask extends Task {
xzFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".pack.xz");
xzTask = new FileDownloadTask(NetworkUtils.toURL(url + ".pack.xz"),
xzFile, dependencyManager.getProxy(), null, 1);
xzFile, null, 1);
xzTask.setSignificance(TaskSignificance.MINOR);
setSignificance(TaskSignificance.MODERATE);
task = new FileDownloadTask(NetworkUtils.toURL(url),
file, dependencyManager.getProxy(),
file,
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
}

View File

@ -24,7 +24,6 @@ import org.jackhuang.hmcl.task.GetTask;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.NetworkUtils;
import java.net.Proxy;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@ -66,7 +65,7 @@ public final class VersionJsonDownloadTask extends Task {
RemoteVersion<?> remoteVersion = gameVersionList.getVersions(gameVersion).stream().findFirst()
.orElseThrow(() -> new IllegalStateException("Cannot find specific version " + gameVersion + " in remote repository"));
String jsonURL = dependencyManager.getDownloadProvider().injectURL(remoteVersion.getUrl());
dependencies.add(new GetTask(NetworkUtils.toURL(jsonURL), Proxy.NO_PROXY, ID));
dependencies.add(new GetTask(NetworkUtils.toURL(jsonURL), ID));
}
public static final String ID = "raw_version_json";

View File

@ -109,7 +109,7 @@ public final class CurseCompletionTask extends Task {
updateProgress(finished.incrementAndGet(), manifest.getFiles().size());
if (StringUtils.isBlank(file.getFileName())) {
try {
return file.withFileName(NetworkUtils.detectFileName(file.getUrl(), dependencyManager.getProxy()));
return file.withFileName(NetworkUtils.detectFileName(file.getUrl()));
} catch (IOException ioe) {
Logging.LOG.log(Level.WARNING, "Unable to fetch the file name of URL: " + file.getUrl(), ioe);
flag.set(false);
@ -125,7 +125,7 @@ public final class CurseCompletionTask extends Task {
if (StringUtils.isNotBlank(file.getFileName())) {
File dest = new File(run, "mods/" + file.getFileName());
if (!dest.exists())
dependencies.add(new FileDownloadTask(file.getUrl(), dest, dependencyManager.getProxy()));
dependencies.add(new FileDownloadTask(file.getUrl(), dest));
}
// Let this task fail if the curse manifest has not been completed.

View File

@ -31,7 +31,6 @@ import java.io.InputStream;
import java.io.RandomAccessFile;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.security.MessageDigest;
import java.util.logging.Level;
@ -79,7 +78,6 @@ public class FileDownloadTask extends Task {
private final File file;
private final IntegrityCheck integrityCheck;
private final int retry;
private final Proxy proxy;
private final EventManager<FailedEvent<URL>> onFailed = new EventManager<>();
private RandomAccessFile rFile;
private InputStream stream;
@ -89,26 +87,16 @@ public class FileDownloadTask extends Task {
* @param file the location that download to.
*/
public FileDownloadTask(URL url, File file) {
this(url, file, Proxy.NO_PROXY);
this(url, file, null);
}
/**
* @param url the URL of remote file.
* @param file the location that download to.
* @param proxy the proxy.
*/
public FileDownloadTask(URL url, File file, Proxy proxy) {
this(url, file, proxy, null);
}
/**
* @param url the URL of remote file.
* @param file the location that download to.
* @param proxy the proxy.
* @param integrityCheck the integrity check to perform, null if no integrity check is to be performed
*/
public FileDownloadTask(URL url, File file, Proxy proxy, IntegrityCheck integrityCheck) {
this(url, file, proxy, integrityCheck, 5);
public FileDownloadTask(URL url, File file, IntegrityCheck integrityCheck) {
this(url, file, integrityCheck, 5);
}
/**
@ -116,14 +104,12 @@ public class FileDownloadTask extends Task {
* @param file the location that download to.
* @param integrityCheck the integrity check to perform, null if no integrity check is to be performed
* @param retry the times for retrying if downloading fails.
* @param proxy the proxy.
*/
public FileDownloadTask(URL url, File file, Proxy proxy, IntegrityCheck integrityCheck, int retry) {
public FileDownloadTask(URL url, File file, IntegrityCheck integrityCheck, int retry) {
this.url = url;
this.file = file;
this.integrityCheck = integrityCheck;
this.retry = retry;
this.proxy = proxy;
setName(file.getName());
}
@ -174,7 +160,7 @@ public class FileDownloadTask extends Task {
try {
updateProgress(0);
HttpURLConnection con = NetworkUtils.createConnection(url, proxy);
HttpURLConnection con = NetworkUtils.createConnection(url);
con.connect();
if (con.getResponseCode() / 100 != 2)

View File

@ -25,7 +25,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.logging.Level;
@ -41,30 +40,24 @@ public final class GetTask extends TaskResult<String> {
private final URL url;
private final Charset charset;
private final int retry;
private final Proxy proxy;
private final String id;
public GetTask(URL url) {
this(url, Proxy.NO_PROXY);
this(url, ID);
}
public GetTask(URL url, Proxy proxy) {
this(url, proxy, ID);
public GetTask(URL url, String id) {
this(url, id, UTF_8);
}
public GetTask(URL url, Proxy proxy, String id) {
this(url, proxy, id, UTF_8);
public GetTask(URL url, String id, Charset charset) {
this(url, id, charset, 5);
}
public GetTask(URL url, Proxy proxy, String id, Charset charset) {
this(url, proxy, id, charset, 5);
}
public GetTask(URL url, Proxy proxy, String id, Charset charset, int retry) {
public GetTask(URL url, String id, Charset charset, int retry) {
this.url = url;
this.charset = charset;
this.retry = retry;
this.proxy = proxy;
this.id = id;
setName(url.toString());
@ -88,7 +81,7 @@ public final class GetTask extends TaskResult<String> {
Logging.LOG.log(Level.WARNING, "Failed to download, repeat times: " + time);
try {
updateProgress(0);
HttpURLConnection conn = NetworkUtils.createConnection(url, proxy);
HttpURLConnection conn = NetworkUtils.createConnection(url);
InputStream input = conn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[IOUtils.DEFAULT_BUFFER_SIZE];

View File

@ -48,8 +48,8 @@ public final class NetworkUtils {
NetworkUtils.userAgentSupplier = Objects.requireNonNull(userAgentSupplier);
}
public static HttpURLConnection createConnection(URL url, Proxy proxy) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
public static HttpURLConnection createConnection(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setConnectTimeout(15000);
@ -59,11 +59,7 @@ public final class NetworkUtils {
}
public static String doGet(URL url) throws IOException {
return IOUtils.readFullyAsString(createConnection(url, Proxy.NO_PROXY).getInputStream());
}
public static String doGet(URL url, Proxy proxy) throws IOException {
return IOUtils.readFullyAsString(createConnection(url, proxy).getInputStream());
return IOUtils.readFullyAsString(createConnection(url).getInputStream());
}
public static String doPost(URL u, Map<String, String> params) throws IOException {
@ -80,14 +76,10 @@ public final class NetworkUtils {
return doPost(u, post, "application/x-www-form-urlencoded");
}
public static String doPost(URL u, String post, String contentType) throws IOException {
return doPost(u, post, contentType, Proxy.NO_PROXY);
}
public static String doPost(URL url, String post, String contentType, Proxy proxy) throws IOException {
public static String doPost(URL url, String post, String contentType) throws IOException {
byte[] bytes = post.getBytes(UTF_8);
HttpURLConnection con = createConnection(url, proxy);
HttpURLConnection con = createConnection(url);
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("Content-Type", contentType + "; charset=utf-8");
@ -120,11 +112,7 @@ public final class NetworkUtils {
}
public static String detectFileName(URL url) throws IOException {
return detectFileName(url, Proxy.NO_PROXY);
}
public static String detectFileName(URL url, Proxy proxy) throws IOException {
HttpURLConnection conn = createConnection(url, proxy);
HttpURLConnection conn = createConnection(url);
conn.connect();
if (conn.getResponseCode() / 100 != 2)
throw new IOException("Response code " + conn.getResponseCode());