Use http.agent to set useragent

This commit is contained in:
yushijinhun 2018-09-22 12:30:33 +08:00
parent b15291dc57
commit 74e3a9e2d1
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
2 changed files with 1 additions and 17 deletions

View File

@ -17,16 +17,12 @@
*/
package org.jackhuang.hmcl;
import org.jackhuang.hmcl.setting.ConfigHolder;
import org.jackhuang.hmcl.upgrade.UpdateHandler;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
@ -40,6 +36,7 @@ public final class Main {
public static void main(String[] args) {
System.setProperty("java.net.useSystemProxies", "true");
System.setProperty("http.agent", "HMCL/" + Metadata.VERSION);
checkJavaFX();
checkDirectoryPath();

View File

@ -22,8 +22,6 @@ import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Supplier;
import org.jackhuang.hmcl.util.Lang;
@ -39,16 +37,6 @@ public final class NetworkUtils {
private NetworkUtils() {
}
private static Supplier<String> userAgentSupplier = () -> "HMCLCore";
public static String getUserAgent() {
return userAgentSupplier.get();
}
public static void setUserAgentSupplier(Supplier<String> userAgentSupplier) {
NetworkUtils.userAgentSupplier = Objects.requireNonNull(userAgentSupplier);
}
public static String withQuery(String baseUrl, Map<String, String> params) {
try {
StringBuilder sb = new StringBuilder(baseUrl);
@ -76,7 +64,6 @@ public final class NetworkUtils {
connection.setUseCaches(false);
connection.setConnectTimeout(15000);
connection.setReadTimeout(15000);
connection.setRequestProperty("User-Agent", getUserAgent());
return connection;
}