修复部分请求头中 Accept-Language 字段包含 Java 版本的问题 (#5508)
This commit is contained in:
@@ -212,7 +212,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
do {
|
do {
|
||||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(currentURI)
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(currentURI)
|
||||||
.timeout(Duration.ofMillis(NetworkUtils.TIME_OUT))
|
.timeout(Duration.ofMillis(NetworkUtils.TIME_OUT))
|
||||||
.header("User-Agent", Holder.USER_AGENT);
|
.header("User-Agent", NetworkUtils.USER_AGENT);
|
||||||
|
|
||||||
headers.forEach(requestBuilder::header);
|
headers.forEach(requestBuilder::header);
|
||||||
response = Holder.HTTP_CLIENT.send(requestBuilder.build(), BODY_HANDLER);
|
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.
|
/// Ensure that [#HTTP_CLIENT] is initialized after ProxyManager has been initialized.
|
||||||
private static final class Holder {
|
private static final class Holder {
|
||||||
private static final HttpClient HTTP_CLIENT;
|
private static final HttpClient HTTP_CLIENT;
|
||||||
private static final String USER_AGENT = System.getProperty("http.agent", "HMCL");
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
|||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public final class NetworkUtils {
|
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 PARAMETER_SEPARATOR = "&";
|
||||||
public static final String NAME_VALUE_SEPARATOR = "=";
|
public static final String NAME_VALUE_SEPARATOR = "=";
|
||||||
public static final int TIME_OUT = 8000;
|
public static final int TIME_OUT = 8000;
|
||||||
@@ -168,6 +170,7 @@ public final class NetworkUtils {
|
|||||||
connection.setReadTimeout(TIME_OUT);
|
connection.setReadTimeout(TIME_OUT);
|
||||||
if (connection instanceof HttpURLConnection httpConnection) {
|
if (connection instanceof HttpURLConnection httpConnection) {
|
||||||
httpConnection.setRequestProperty("Accept-Language", Locale.getDefault().toLanguageTag());
|
httpConnection.setRequestProperty("Accept-Language", Locale.getDefault().toLanguageTag());
|
||||||
|
httpConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpConnection.setInstanceFollowRedirects(false);
|
httpConnection.setInstanceFollowRedirects(false);
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
|
|||||||
Reference in New Issue
Block a user