-
Notifications
You must be signed in to change notification settings - Fork 827
修复部分请求头中 Accept-Language 字段包含 Java 版本的问题 #5508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
There was a problem hiding this 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.
| public static final String USER_AGENT = System.getProperty("http.agent", "HMCL"); | ||
|
|
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
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/.
| if (connection instanceof HttpURLConnection httpConnection) { | ||
| httpConnection.setRequestProperty("Accept-Language", Locale.getDefault().toLanguageTag()); | ||
| httpConnection.setRequestProperty("User-Agent", USER_AGENT); | ||
| httpConnection.setInstanceFollowRedirects(false); | ||
| } |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
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.
No description provided.