Skip to content

Conversation

@Glavo
Copy link
Member

@Glavo Glavo commented Feb 9, 2026

No description provided.

CiiLu and others added 2 commits February 10, 2026 00:41
Resolves HMCL-dev#5135

Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: Glavo <zjx001202@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在统一并修复网络请求的默认请求头设置,避免部分请求在未显式设置时使用不符合预期的默认值(PR 标题提到的 “Accept-Language 包含 Java 版本” 问题)。

Changes:

  • NetworkUtils 中新增统一的 USER_AGENT 常量,并在 HttpURLConnection 连接创建时设置 User-Agent 请求头
  • FetchTask 下载请求改为使用 NetworkUtils.USER_AGENT,并移除内部 Holder.USER_AGENT

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java 引入并在 createConnection 中应用统一的 User-Agent(同时保留 Accept-Language 设置)
HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java 下载请求使用统一的 User-Agent 常量并清理重复定义

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to +44
public static final String USER_AGENT = System.getProperty("http.agent", "HMCL");

Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USER_AGENT is derived from System.getProperty("http.agent"), which on many JDKs defaults to something like Java/<version>. Given the PR title is about removing Java version leakage, this likely does not fix the issue and may even enforce sending the Java version in more requests. Consider using an HMCL-specific UA string by default (optionally allowing override via a dedicated property), or explicitly overriding values that start with Java/.

Copilot uses AI. Check for mistakes.
Comment on lines 171 to 175
if (connection instanceof HttpURLConnection httpConnection) {
httpConnection.setRequestProperty("Accept-Language", Locale.getDefault().toLanguageTag());
httpConnection.setRequestProperty("User-Agent", USER_AGENT);
httpConnection.setInstanceFollowRedirects(false);
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createConnection now sets a default User-Agent, but there’s no test coverage asserting the request properties set on HttpURLConnection (at least for Accept-Language/User-Agent). Since NetworkUtils already has unit tests, it would be good to add a focused test (e.g., via a custom URLStreamHandler/mock URLConnection) to prevent regressions in these default headers.

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit 2e26b14 into HMCL-dev:main Feb 10, 2026
2 checks passed
@Glavo Glavo deleted the agent branch February 10, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants