修复部分请求头中 Accept-Language 字段包含 Java 版本的问题 (#5508)

This commit is contained in:
Glavo
2026-02-10 22:39:22 +08:00
committed by GitHub
parent b7fbebae43
commit 2e26b14322
2 changed files with 4 additions and 2 deletions

View File

@@ -212,7 +212,7 @@ public abstract class FetchTask<T> extends Task<T> {
do {
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(currentURI)
.timeout(Duration.ofMillis(NetworkUtils.TIME_OUT))
.header("User-Agent", Holder.USER_AGENT);
.header("User-Agent", NetworkUtils.USER_AGENT);
headers.forEach(requestBuilder::header);
response = Holder.HTTP_CLIENT.send(requestBuilder.build(), BODY_HANDLER);
@@ -518,7 +518,6 @@ public abstract class FetchTask<T> extends Task<T> {
/// Ensure that [#HTTP_CLIENT] is initialized after ProxyManager has been initialized.
private static final class Holder {
private static final HttpClient HTTP_CLIENT;
private static final String USER_AGENT = System.getProperty("http.agent", "HMCL");
static {
if (!initialized) {

View File

@@ -40,6 +40,8 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG;
* @author huangyuhui
*/
public final class NetworkUtils {
public static final String USER_AGENT = System.getProperty("http.agent", "HMCL");
public static final String PARAMETER_SEPARATOR = "&";
public static final String NAME_VALUE_SEPARATOR = "=";
public static final int TIME_OUT = 8000;
@@ -168,6 +170,7 @@ public final class NetworkUtils {
connection.setReadTimeout(TIME_OUT);
if (connection instanceof HttpURLConnection httpConnection) {
httpConnection.setRequestProperty("Accept-Language", Locale.getDefault().toLanguageTag());
httpConnection.setRequestProperty("User-Agent", USER_AGENT);
httpConnection.setInstanceFollowRedirects(false);
}
return connection;