fix(frontend): recommend socks5h proxy URLs#48
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to detect and recommend converting socks5:// proxy URLs to socks5h:// in the LLM gateway admin frontend, ensuring DNS resolution is handled by the proxy server. Feedback was provided to refactor the helper functions for more idiomatic Rust and simplified control flow.
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.
| fn recommended_socks5h_proxy_url(raw: &str) -> Option<String> { | ||
| let trimmed = raw.trim(); | ||
| let prefix_len = "socks5://".len(); | ||
| if trimmed | ||
| .get(..prefix_len) | ||
| .is_some_and(|prefix| prefix.eq_ignore_ascii_case("socks5://")) | ||
| { | ||
| Some(format!("socks5h://{}", &trimmed[prefix_len..])) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| fn proxy_url_after_socks5h_confirmation(raw: &str) -> String { | ||
| let trimmed = raw.trim(); | ||
| let Some(recommended) = recommended_socks5h_proxy_url(trimmed) else { | ||
| return trimmed.to_string(); | ||
| }; | ||
| if confirm_destructive( | ||
| "检测到当前代理 URL 使用 socks5://。\n\n对 ChatGPT/Codex 这类依赖 CDN/DNS \ | ||
| 路由的上游,推荐使用 socks5h://,让代理服务器解析域名,避免本机 DNS 解析出的 IP \ | ||
| 在代理出口不可用。\n\n点击“确定”自动转换为 socks5h://;点击“取消”继续保留 socks5://。", | ||
| ) { | ||
| recommended | ||
| } else { | ||
| trimmed.to_string() | ||
| } | ||
| } |
There was a problem hiding this comment.
Refactoring Opportunity: Idiomatic Rust & Simplified Control Flow
We can make these helper functions more idiomatic and readable by:
- Using the
?operator onOptionto simplify the case-insensitive prefix check and avoid nested closures (is_some_and). - Eliminating redundant
.trim()calls on the input string. - Simplifying the control flow in
proxy_url_after_socks5h_confirmationto avoid early returns and nestedif/elseblocks.
Here is a cleaner and more idiomatic implementation:
fn recommended_socks5h_proxy_url(raw: &str) -> Option<String> {
let trimmed = raw.trim();
let prefix = "socks5://";
if trimmed.get(..prefix.len())?.eq_ignore_ascii_case(prefix) {
Some(format!("socks5h://{}", &trimmed[prefix.len()..]))
} else {
None
}
}
fn proxy_url_after_socks5h_confirmation(raw: &str) -> String {
if let Some(recommended) = recommended_socks5h_proxy_url(raw) {
if confirm_destructive(
"检测到当前代理 URL 使用 socks5://。\n\n对 ChatGPT/Codex 这类依赖 CDN/DNS \\
路由的上游,推荐使用 socks5h://,让代理服务器解析域名,避免本机 DNS 解析出的 IP \\
在代理出口不可用。\n\n点击“确定”自动转换为 socks5h://;点击“取消”继续保留 socks5://。",
) {
return recommended;
}
}
raw.trim().to_string()
}
Summary
Add an admin frontend prompt when a proxy URL uses
socks5://, recommendingsocks5h://for Codex/ChatGPT upstream connectivity.Root cause
socks5://resolves the upstream hostname on the local machine, whilesocks5h://delegates DNS resolution to the proxy server. For ChatGPT/Codex CDN routing, local DNS can select an address that is not reachable from the proxy exit path.What changed
socks5://proxy URLs during proxy creation and editing.socks5h://or keep the original value.Test Plan
CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo test -p static-flow-frontend --jobs 4CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo clippy -p static-flow-frontend --jobs 4 -- -D warningsgit diff --check -- crates/frontend/src/pages/admin_llm_gateway.rs