Skip to content

feat(remote): read a port, host:port or URL typed into the ports page (#2231) - #156

Merged
xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-forward-address
Nov 21, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-forward-address

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联 Issue

1lck/Lithe-IDEA#2231(远程开发完整设计):端口页的远端端口要带上 IP,转发目标要能写网址,不只是 IP+端口。桌面端在 1lck/Lithe-IDEA#2286 上接入。

类型

  • feat:新增 remote.parseForwardAddress,把端口页里输入的端口、host:port 或网址解析成转发目标

改动说明

解析(新文件 crates/remote/src/client/forward_address.rs)

  • 不需要连接,也不做 DNS 解析。接受三种写法:
    • 只写端口(3000),目标是主机上的 localhost;
    • host:port,IPv6 要加方括号([::1]:5432);
    • 网址 scheme://host[:port][/path][?query][#fragment]。
  • 网址没写端口时按协议补默认端口:http、ws 用 80,https、wss 用 443;其他协议(如 postgres)必须写端口。
  • 结果是 ForwardAddress { targetHost, targetPort, scheme?, path? }:
    • targetHost 不带方括号,主机名转成小写,校验沿用 ForwardSet 的目标主机规则(新增 forward_set::is_target_host),所以能解析的地址一定能转发;
    • scheme 和 path 只在输入里有时才返回,path 是主机和端口后面的部分,空或只有 / 时省略。桌面端用它们按原来的协议和路径打开转发后的地址。
  • 拒绝时每种情况只对应一个原因:empty、tooLong(超过 2048 字节)、malformed(含空白或控制字符)、scheme、credentials、host、port。
  • 网址里带用户名或密码(user:pass@host)一律拒绝(credentials),不保存、不回显,避免密码出现在端口列表、日志或复制内容里。

命令

  • crates/workspace/src/forwards.rs 新增 parse_address,请求是 { text },拒绝未知字段。拒绝时返回 invalid_request,details 为 { field: "text", reason },错误信息不包含输入原文。
  • crates/core 新增 RemoteCommand::ParseForwardAddress、命令名映射和 dispatcher 分支,只做转接。

契约(rust/contracts/rust-core-api.md)

  • 命令表加一行;端口转发一节加请求/结果一行,并说明三种写法、默认端口、返回字段和拒绝原因。

范围

  • 解析逻辑只在 crates/remote;crates/workspace 和 crates/core 只做转接。
  • 转发本身不变:仍然是本机回环地址监听、主机拨号,服务端仍然不在 TCP 上监听。“主机上监听、转到另一台服务器”这类规则的设计写进桌面端仓库的 Agent Note,本 PR 不实现。

验证

  • cargo test -p lithe-remote:104 个通过,其中新增 7 个 forward_address 单测,覆盖只写端口、host:port、网址补默认端口、纯数字当端口、拒绝用户名密码、长度与空白边界、每种拒绝原因各不相同。
  • cargo test -p lithe-core --lib:888 个通过。connection_window_helpers_answer_through_the_dispatcher 新增 remote.parseForwardAddress 的调用,覆盖网址、只写端口、拒绝用户名密码(且错误里不含密码)和未知字段。
  • cargo test -p lithe-workspace:47 个通过。
  • cargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-targets --all-features -- -D warnings:通过。
  • cargo fmt --all --check、scripts/rust-core/verify-rust-core-comments.sh:通过。
  • Windows 目标(x86_64-pc-windows-msvc)的 clippy 本机没跑成:libsqlite3-sys 需要 Windows 的 C 编译器,本机没有。新增代码是纯字符串解析,没有平台分支,交给 CI 的 Windows 任务检查。

… (Refs 1lck/Lithe-IDEA#2231)

remote.parseForwardAddress turns what the user types into a forward target
without a connection: a port alone on localhost, host:port, or a URL whose
scheme and path the page keeps to open the forwarded address the same way.
User names and passwords are refused, not kept; each refusal names one
reason in details.
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