[Chore] CF 下载文件也使用 API Key#6169
Conversation
|
要审查就自己运行/gemini review [doge] |
不应该是 3.6 么? 3.15 下个月底就过期了,要给这个分支移植吗? |
额那就是我记错了 |
There was a problem hiding this comment.
Code Review
This pull request refactors the handling of the CurseForge API key by exposing it as a public constant and introducing a centralized helper method, NetworkUtils.newRequestBuilder, to automatically inject the API key header for CurseForge domains. Feedback on the changes highlights a potential NullPointerException in NetworkUtils.newRequestBuilder when processing URIs with a null host, recommending a defensive null-check.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| public static java.net.http.HttpRequest.Builder newRequestBuilder(URI uri) { | ||
| var builder = java.net.http.HttpRequest.newBuilder(uri); | ||
| var apiKey = API_KEYS.get(uri.getHost().toLowerCase(Locale.ROOT)); | ||
| if (StringUtils.isNotBlank(apiKey)) | ||
| builder.header("x-api-key", apiKey); | ||
| return builder; | ||
| } |
There was a problem hiding this comment.
If uri.getHost() returns null (which can happen for non-hierarchical URIs or URIs without a host component), calling toLowerCase() on it will throw a NullPointerException. Guard against a null host to ensure defensive programming and avoid runtime crashes.
public static java.net.http.HttpRequest.Builder newRequestBuilder(URI uri) {
var builder = java.net.http.HttpRequest.newBuilder(uri);
String host = uri.getHost();
if (host != null) {
var apiKey = API_KEYS.get(host.toLowerCase(Locale.ROOT));
if (StringUtils.isNotBlank(apiKey)) {
builder.header("x-api-key", apiKey);
}
}
return builder;
}
Closes #6167
可能需要 backport 到 3.6 等版本