Skip to content

fix(frontend): recommend socks5h proxy URLs#48

Merged
acking-you merged 1 commit into
masterfrom
fix/codex-socks5h-proxy-hint
Jun 23, 2026
Merged

fix(frontend): recommend socks5h proxy URLs#48
acking-you merged 1 commit into
masterfrom
fix/codex-socks5h-proxy-hint

Conversation

@acking-you

Copy link
Copy Markdown
Owner

Summary

Add an admin frontend prompt when a proxy URL uses socks5://, recommending socks5h:// for Codex/ChatGPT upstream connectivity.

Root cause

socks5:// resolves the upstream hostname on the local machine, while socks5h:// 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

  • Detect socks5:// proxy URLs during proxy creation and editing.
  • Prompt the admin to convert to socks5h:// or keep the original value.
  • Add unit coverage for conversion, ignored schemes, and non-ASCII invalid input.

Test Plan

  • CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo test -p static-flow-frontend --jobs 4
  • CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo clippy -p static-flow-frontend --jobs 4 -- -D warnings
  • git diff --check -- crates/frontend/src/pages/admin_llm_gateway.rs

@acking-you acking-you merged commit afb258f into master Jun 23, 2026
3 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +821 to +848
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()
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Refactoring Opportunity: Idiomatic Rust & Simplified Control Flow

We can make these helper functions more idiomatic and readable by:

  1. Using the ? operator on Option to simplify the case-insensitive prefix check and avoid nested closures (is_some_and).
  2. Eliminating redundant .trim() calls on the input string.
  3. Simplifying the control flow in proxy_url_after_socks5h_confirmation to avoid early returns and nested if/else blocks.

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()
}

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.

1 participant