mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-30 14:39:56 +08:00
Use http.agent to set useragent
This commit is contained in:
parent
b15291dc57
commit
74e3a9e2d1
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user