mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-15 14:56:05 -04:00
Remove proxy from FileDownloadTask/GetTask/NetworkUtils
This commit is contained in:
parent
2f6c7e1ce2
commit
06806bd383
@ -154,7 +154,7 @@ public final class AccountHelper {
|
|||||||
File file = getSkinFile(profile.getId());
|
File file = getSkinFile(profile.getId());
|
||||||
if (!refresh && file.exists())
|
if (!refresh && file.exists())
|
||||||
return;
|
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 {
|
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());
|
File file = getSkinFile(account.getUUID());
|
||||||
if (!refresh && file.exists())
|
if (!refresh && file.exists())
|
||||||
return;
|
return;
|
||||||
new FileDownloadTask(NetworkUtils.toURL(url), file, proxy).run();
|
new FileDownloadTask(NetworkUtils.toURL(url), file).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Image scale(String url, double scaleRatio) {
|
public static Image scale(String url, double scaleRatio) {
|
||||||
|
@ -71,7 +71,6 @@ public class HMCLGameDownloadTask extends Task {
|
|||||||
dependencies.add(new FileDownloadTask(
|
dependencies.add(new FileDownloadTask(
|
||||||
NetworkUtils.toURL(profile.getDependency().getDownloadProvider().injectURL(version.getDownloadInfo().getUrl())),
|
NetworkUtils.toURL(profile.getDependency().getDownloadProvider().injectURL(version.getDownloadInfo().getUrl())),
|
||||||
cache,
|
cache,
|
||||||
profile.getDependency().getProxy(),
|
|
||||||
new IntegrityCheck("SHA-1", version.getDownloadInfo().getSha1())
|
new IntegrityCheck("SHA-1", version.getDownloadInfo().getSha1())
|
||||||
).then(Task.of(v -> FileUtils.copyFile(cache, jar))));
|
).then(Task.of(v -> FileUtils.copyFile(cache, jar))));
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Task> getDependents() {
|
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
|
@Override
|
||||||
@ -235,7 +235,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Task> getDependents() {
|
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
|
@Override
|
||||||
|
@ -20,7 +20,6 @@ package org.jackhuang.hmcl.auth.authlibinjector;
|
|||||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -81,7 +80,7 @@ public class AuthlibInjectorDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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"))
|
Optional.ofNullable(latest.checksums.get("sha256"))
|
||||||
.map(checksum -> new IntegrityCheck("SHA-256", checksum))
|
.map(checksum -> new IntegrityCheck("SHA-256", checksum))
|
||||||
.orElse(null))
|
.orElse(null))
|
||||||
|
@ -107,7 +107,7 @@ public final class GameAssetDownloadTask extends Task {
|
|||||||
flag = !file.exists();
|
flag = !file.exists();
|
||||||
}
|
}
|
||||||
if (flag) {
|
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());
|
task.setName(assetObject.getHash());
|
||||||
dependencies.add(task);
|
dependencies.add(task);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public final class GameAssetIndexDownloadTask extends Task {
|
|||||||
File assetIndexFile = dependencyManager.getGameRepository().getIndexFile(version.getId(), assetIndexInfo.getId());
|
File assetIndexFile = dependencyManager.getGameRepository().getIndexFile(version.getId(), assetIndexInfo.getId());
|
||||||
dependencies.add(new FileDownloadTask(
|
dependencies.add(new FileDownloadTask(
|
||||||
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(assetIndexInfo.getUrl())),
|
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(assetIndexInfo.getUrl())),
|
||||||
assetIndexFile, dependencyManager.getProxy()
|
assetIndexFile
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ public final class GameDownloadTask extends Task {
|
|||||||
dependencies.add(new FileDownloadTask(
|
dependencies.add(new FileDownloadTask(
|
||||||
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(version.getDownloadInfo().getUrl())),
|
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(version.getDownloadInfo().getUrl())),
|
||||||
jar,
|
jar,
|
||||||
dependencyManager.getProxy(),
|
|
||||||
new IntegrityCheck("SHA-1", version.getDownloadInfo().getSha1())
|
new IntegrityCheck("SHA-1", version.getDownloadInfo().getSha1())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public final class GameLoggingDownloadTask extends Task {
|
|||||||
LoggingInfo logging = version.getLogging().get(DownloadType.CLIENT);
|
LoggingInfo logging = version.getLogging().get(DownloadType.CLIENT);
|
||||||
File file = dependencyManager.getGameRepository().getLoggingObject(version.getId(), version.getAssetIndex().getId(), logging);
|
File file = dependencyManager.getGameRepository().getLoggingObject(version.getId(), version.getAssetIndex().getId(), logging);
|
||||||
if (!file.exists())
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,13 @@ public final class LibraryDownloadTask extends Task {
|
|||||||
xzFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".pack.xz");
|
xzFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".pack.xz");
|
||||||
|
|
||||||
xzTask = new FileDownloadTask(NetworkUtils.toURL(url + ".pack.xz"),
|
xzTask = new FileDownloadTask(NetworkUtils.toURL(url + ".pack.xz"),
|
||||||
xzFile, dependencyManager.getProxy(), null, 1);
|
xzFile, null, 1);
|
||||||
xzTask.setSignificance(TaskSignificance.MINOR);
|
xzTask.setSignificance(TaskSignificance.MINOR);
|
||||||
|
|
||||||
setSignificance(TaskSignificance.MODERATE);
|
setSignificance(TaskSignificance.MODERATE);
|
||||||
|
|
||||||
task = new FileDownloadTask(NetworkUtils.toURL(url),
|
task = new FileDownloadTask(NetworkUtils.toURL(url),
|
||||||
file, dependencyManager.getProxy(),
|
file,
|
||||||
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
|
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import org.jackhuang.hmcl.task.GetTask;
|
|||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||||
|
|
||||||
import java.net.Proxy;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -66,7 +65,7 @@ public final class VersionJsonDownloadTask extends Task {
|
|||||||
RemoteVersion<?> remoteVersion = gameVersionList.getVersions(gameVersion).stream().findFirst()
|
RemoteVersion<?> remoteVersion = gameVersionList.getVersions(gameVersion).stream().findFirst()
|
||||||
.orElseThrow(() -> new IllegalStateException("Cannot find specific version " + gameVersion + " in remote repository"));
|
.orElseThrow(() -> new IllegalStateException("Cannot find specific version " + gameVersion + " in remote repository"));
|
||||||
String jsonURL = dependencyManager.getDownloadProvider().injectURL(remoteVersion.getUrl());
|
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";
|
public static final String ID = "raw_version_json";
|
||||||
|
@ -109,7 +109,7 @@ public final class CurseCompletionTask extends Task {
|
|||||||
updateProgress(finished.incrementAndGet(), manifest.getFiles().size());
|
updateProgress(finished.incrementAndGet(), manifest.getFiles().size());
|
||||||
if (StringUtils.isBlank(file.getFileName())) {
|
if (StringUtils.isBlank(file.getFileName())) {
|
||||||
try {
|
try {
|
||||||
return file.withFileName(NetworkUtils.detectFileName(file.getUrl(), dependencyManager.getProxy()));
|
return file.withFileName(NetworkUtils.detectFileName(file.getUrl()));
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Logging.LOG.log(Level.WARNING, "Unable to fetch the file name of URL: " + file.getUrl(), ioe);
|
Logging.LOG.log(Level.WARNING, "Unable to fetch the file name of URL: " + file.getUrl(), ioe);
|
||||||
flag.set(false);
|
flag.set(false);
|
||||||
@ -125,7 +125,7 @@ public final class CurseCompletionTask extends Task {
|
|||||||
if (StringUtils.isNotBlank(file.getFileName())) {
|
if (StringUtils.isNotBlank(file.getFileName())) {
|
||||||
File dest = new File(run, "mods/" + file.getFileName());
|
File dest = new File(run, "mods/" + file.getFileName());
|
||||||
if (!dest.exists())
|
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.
|
// Let this task fail if the curse manifest has not been completed.
|
||||||
|
@ -31,7 +31,6 @@ import java.io.InputStream;
|
|||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -79,7 +78,6 @@ public class FileDownloadTask extends Task {
|
|||||||
private final File file;
|
private final File file;
|
||||||
private final IntegrityCheck integrityCheck;
|
private final IntegrityCheck integrityCheck;
|
||||||
private final int retry;
|
private final int retry;
|
||||||
private final Proxy proxy;
|
|
||||||
private final EventManager<FailedEvent<URL>> onFailed = new EventManager<>();
|
private final EventManager<FailedEvent<URL>> onFailed = new EventManager<>();
|
||||||
private RandomAccessFile rFile;
|
private RandomAccessFile rFile;
|
||||||
private InputStream stream;
|
private InputStream stream;
|
||||||
@ -89,26 +87,16 @@ public class FileDownloadTask extends Task {
|
|||||||
* @param file the location that download to.
|
* @param file the location that download to.
|
||||||
*/
|
*/
|
||||||
public FileDownloadTask(URL url, File file) {
|
public FileDownloadTask(URL url, File file) {
|
||||||
this(url, file, Proxy.NO_PROXY);
|
this(url, file, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param url the URL of remote file.
|
* @param url the URL of remote file.
|
||||||
* @param file the location that download to.
|
* @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
|
* @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) {
|
public FileDownloadTask(URL url, File file, IntegrityCheck integrityCheck) {
|
||||||
this(url, file, proxy, integrityCheck, 5);
|
this(url, file, integrityCheck, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,14 +104,12 @@ public class FileDownloadTask extends Task {
|
|||||||
* @param file the location that download to.
|
* @param file the location that download to.
|
||||||
* @param integrityCheck the integrity check to perform, null if no integrity check is to be performed
|
* @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 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.url = url;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.integrityCheck = integrityCheck;
|
this.integrityCheck = integrityCheck;
|
||||||
this.retry = retry;
|
this.retry = retry;
|
||||||
this.proxy = proxy;
|
|
||||||
|
|
||||||
setName(file.getName());
|
setName(file.getName());
|
||||||
}
|
}
|
||||||
@ -174,7 +160,7 @@ public class FileDownloadTask extends Task {
|
|||||||
try {
|
try {
|
||||||
updateProgress(0);
|
updateProgress(0);
|
||||||
|
|
||||||
HttpURLConnection con = NetworkUtils.createConnection(url, proxy);
|
HttpURLConnection con = NetworkUtils.createConnection(url);
|
||||||
con.connect();
|
con.connect();
|
||||||
|
|
||||||
if (con.getResponseCode() / 100 != 2)
|
if (con.getResponseCode() / 100 != 2)
|
||||||
|
@ -25,7 +25,6 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -41,30 +40,24 @@ public final class GetTask extends TaskResult<String> {
|
|||||||
private final URL url;
|
private final URL url;
|
||||||
private final Charset charset;
|
private final Charset charset;
|
||||||
private final int retry;
|
private final int retry;
|
||||||
private final Proxy proxy;
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
public GetTask(URL url) {
|
public GetTask(URL url) {
|
||||||
this(url, Proxy.NO_PROXY);
|
this(url, ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetTask(URL url, Proxy proxy) {
|
public GetTask(URL url, String id) {
|
||||||
this(url, proxy, ID);
|
this(url, id, UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetTask(URL url, Proxy proxy, String id) {
|
public GetTask(URL url, String id, Charset charset) {
|
||||||
this(url, proxy, id, UTF_8);
|
this(url, id, charset, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetTask(URL url, Proxy proxy, String id, Charset charset) {
|
public GetTask(URL url, String id, Charset charset, int retry) {
|
||||||
this(url, proxy, id, charset, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GetTask(URL url, Proxy proxy, String id, Charset charset, int retry) {
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
this.retry = retry;
|
this.retry = retry;
|
||||||
this.proxy = proxy;
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
setName(url.toString());
|
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);
|
Logging.LOG.log(Level.WARNING, "Failed to download, repeat times: " + time);
|
||||||
try {
|
try {
|
||||||
updateProgress(0);
|
updateProgress(0);
|
||||||
HttpURLConnection conn = NetworkUtils.createConnection(url, proxy);
|
HttpURLConnection conn = NetworkUtils.createConnection(url);
|
||||||
InputStream input = conn.getInputStream();
|
InputStream input = conn.getInputStream();
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
byte[] buf = new byte[IOUtils.DEFAULT_BUFFER_SIZE];
|
byte[] buf = new byte[IOUtils.DEFAULT_BUFFER_SIZE];
|
||||||
|
@ -48,8 +48,8 @@ public final class NetworkUtils {
|
|||||||
NetworkUtils.userAgentSupplier = Objects.requireNonNull(userAgentSupplier);
|
NetworkUtils.userAgentSupplier = Objects.requireNonNull(userAgentSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpURLConnection createConnection(URL url, Proxy proxy) throws IOException {
|
public static HttpURLConnection createConnection(URL url) throws IOException {
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
connection.setConnectTimeout(15000);
|
connection.setConnectTimeout(15000);
|
||||||
@ -59,11 +59,7 @@ public final class NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String doGet(URL url) throws IOException {
|
public static String doGet(URL url) throws IOException {
|
||||||
return IOUtils.readFullyAsString(createConnection(url, Proxy.NO_PROXY).getInputStream());
|
return IOUtils.readFullyAsString(createConnection(url).getInputStream());
|
||||||
}
|
|
||||||
|
|
||||||
public static String doGet(URL url, Proxy proxy) throws IOException {
|
|
||||||
return IOUtils.readFullyAsString(createConnection(url, proxy).getInputStream());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String doPost(URL u, Map<String, String> params) throws IOException {
|
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");
|
return doPost(u, post, "application/x-www-form-urlencoded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String doPost(URL u, String post, String contentType) throws IOException {
|
public static String doPost(URL url, 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 {
|
|
||||||
byte[] bytes = post.getBytes(UTF_8);
|
byte[] bytes = post.getBytes(UTF_8);
|
||||||
|
|
||||||
HttpURLConnection con = createConnection(url, proxy);
|
HttpURLConnection con = createConnection(url);
|
||||||
con.setRequestMethod("POST");
|
con.setRequestMethod("POST");
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
con.setRequestProperty("Content-Type", contentType + "; charset=utf-8");
|
con.setRequestProperty("Content-Type", contentType + "; charset=utf-8");
|
||||||
@ -120,11 +112,7 @@ public final class NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String detectFileName(URL url) throws IOException {
|
public static String detectFileName(URL url) throws IOException {
|
||||||
return detectFileName(url, Proxy.NO_PROXY);
|
HttpURLConnection conn = createConnection(url);
|
||||||
}
|
|
||||||
|
|
||||||
public static String detectFileName(URL url, Proxy proxy) throws IOException {
|
|
||||||
HttpURLConnection conn = createConnection(url, proxy);
|
|
||||||
conn.connect();
|
conn.connect();
|
||||||
if (conn.getResponseCode() / 100 != 2)
|
if (conn.getResponseCode() / 100 != 2)
|
||||||
throw new IOException("Response code " + conn.getResponseCode());
|
throw new IOException("Response code " + conn.getResponseCode());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user