{"record":{"id":"8da1ed3170afc981","repo":"BigPizzaV3/CodexPlusPlus","slug":"base-url-8da1ed","errorCode":null,"errorMessage":"Base URL 缺少主机名","messagePattern":"Base URL 缺少主机名","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/routes.rs","lineNumber":794,"sourceCode":"        \"status\": \"ok\",\n        \"http_status\": http_status,\n        \"ok\": ok,\n        \"body_text\": body_text,\n        \"body_json\": body_json,\n    }))\n}\n\nfn validate_llm_proxy_url(raw: &str) -> anyhow::Result<reqwest::Url> {\n    let url = reqwest::Url::parse(raw.trim()).map_err(|_| anyhow::anyhow!(\"Base URL 格式无效\"))?;\n    if url.scheme() != \"https\" {\n        anyhow::bail!(\"Base URL 必须使用 HTTPS\");\n    }\n    if !url.username().is_empty() || url.password().is_some() {\n        anyhow::bail!(\"Base URL 不得包含用户名或密码\");\n    }\n    let host = url\n        .host_str()\n        .ok_or_else(|| anyhow::anyhow!(\"Base URL 缺少主机名\"))?;\n    if is_blocked_llm_proxy_host(host) {\n        anyhow::bail!(\"Base URL 不得指向本机或私有网络\");\n    }\n    Ok(url)\n}\n\nfn is_blocked_llm_proxy_host(host: &str) -> bool {\n    let host = host\n        .trim()\n        .trim_start_matches('[')\n        .trim_end_matches(']')\n        .to_lowercase();\n    if host.is_empty()\n        || host == \"localhost\"\n        || host.ends_with(\".localhost\")\n        || host.ends_with(\".local\")\n    {\n        return true;","sourceCodeStart":776,"sourceCodeEnd":812,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/routes.rs#L776-L812","documentation":"After the URL parses, validate_llm_proxy_url requires a host component. Certain parseable URLs — e.g. \"https://\" alone, or scheme-only forms — yield no host, so url.host_str() returns None and the library raises this error. This prevents issuing requests to a hostless URL.","triggerScenarios":"Passing \"https://\", \"https:///path\", or a URL whose host part is empty/invalid to the LLM proxy Base URL field via llm_proxy_value.","commonSituations":"Truncated paste of a base URL into the profile form; config file edited by hand dropping the host; programmatic config generation bug concatenating scheme and path only.","solutions":["Provide a complete URL with hostname, e.g. \"https://api.example.com/v1\".","Re-copy the provider base URL from the vendor docs and trim truncation.","Check config.toml / saved profile for a partially written base_url value and fix it.","Add client-side validation requiring a non-empty host before submitting."],"exampleFix":"// before\n\"base_url\": \"https://\"\n// after\n\"base_url\": \"https://api.deepseek.com/v1\"","handlingStrategy":"validation","validationCode":"function hasHost(raw: string): boolean {\n  try { return new URL(raw.trim()).hostname.length > 0; }\n  catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.setLlmProxy({ baseUrl });\n} catch (e) {\n  if (String(e).includes('缺少主机名')) {\n    showFieldError('base_url', 'URL 缺少主机名，请填写完整地址');\n  } else { throw e; }\n}","preventionTips":["Require a hostname in URL inputs; reject scheme-only values.","Verify saved profiles contain complete URLs after edits.","Re-copy base URLs from provider docs rather than typing them.","Add round-trip validation after config migration."],"tags":["url","validation","config"],"backgroundTag":"invalid-url-format","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}