Repository navigation
fix(proxydial): preserve buffered CONNECT tunnel data - #102
Closed
idealistichacker wants to merge 1 commit into
Closed
idealistichacker wants to merge 1 commit into
idealistichacker wants to merge 1 commit into
Conversation
Owner
|
据我所知只有smtp这种服务端先呼叫的协议才可能触发这个PR考虑的场景,或者是代理违反协议、在回复后附带了数据 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
HTTP CONNECT 成功后,
http.ReadResponse(bufio.NewReader(connection), request)可能把响应头之后的隧道字节预读进bufio.Reader。当前实现丢弃该 reader,直接返回底层连接,导致预读字节永久丢失。通过本机 SOCKS5 relay 的连接也会经过这条路径。本地复现:假代理在一次写入中发送
200 Connection Established响应头和 256 字节二进制数据,然后关闭连接。修复前,直接调用Dialer和通过StartRelay两种情况均读取到 0/256 字节,EOF。改动
Read继续读取同一 reader。net.Conn。CloseWrite,避免 relay 的半关闭退化为关闭整个连接,截断对端在收到 EOF 后才发送的最后回复。验证
所有网络测试仅监听
127.0.0.1,不连接真实代理、Google 或模型服务,也不读取真实凭据。TestCONNECTPreservesDataAfterResponseHeaders在原实现的 direct / relay 两个子测试均因 0/256 字节、EOF 失败。go test ./internal/proxydial -count=50通过。go test ./internal/proxydial -run TestCONNECT -count=100通过。CGO_ENABLED=1 go test -race -count=50 ./internal/proxydial通过。go test ./internal/config ./internal/i18n ./internal/proxydial通过(i18n 无测试文件)。go vet ./internal/config ./internal/i18n ./internal/proxydial通过。CGO_ENABLED=0 go build ./internal/proxydial、gofmt、git diff --check通过。CloseWrite;对端读到 EOF 后才回传 request,客户端仍读到完整回复。测试通过 channel 等待假代理完成,连接带 deadline;没有用 sleep 判断数据是否已到达。未运行需要 SpiderMonkey/音频等原生组件的应用全量构建/测试,未启动真实浏览器或账号。HTTPS 代理的真实证书握手未单独覆盖;修改位于 HTTP/HTTPS 共用的 CONNECT 响应读取路径。
AI 辅助
代码、回归测试和本 PR 描述由 OpenAI Codex 在账号所有者授权下自主准备。只声明上面实际执行过的验证。