Conversation
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
fix: 更新版本号至2026-08-09并优化XHTTP传输链路和连接管理
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
fix: 更新版本号至2026-08-09并修复链式代理路径末尾斜杠处理
fix: 修复响应URL生成逻辑
There was a problem hiding this comment.
Pull request overview
该 PR 将 beta2.1 分支中自 2026-07-29 以来的 XHTTP 链路优化与混淆增强合并到 main:重构 TCP 传输为双向 pipe 直通以降低 CPU、引入上行合包以减少小包写入开销、增加基于 UUID 派生的 obfs padding 识别/校验与响应注入,并修复链式代理路径末尾 / 导致的解析失效。
Changes:
- 重构 XHTTP(TCP) 数据转发为
request.body -> socket.writable与socket.readable -> response的直通 pipe,并为forwardataTCP增加“仅建立连接”模式与统一清理逻辑。 - 新增上行 Grain 合包流,将小块数据缓冲合并后再写入 socket,降低频繁
writer.write()的开销。 - 引入 XHTTP obfs padding:UUID 派生 header/key、接收端 Huffman 字节长度校验、响应侧自动注入 padding;同时拆分独立 UDP 处理函数并修复链式代理末尾斜杠解析。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
_worker.js |
实现 XHTTP 直通 pipe / 上行合包 / padding 混淆校验与注入、UDP 分支拆分、链式代理解析修复,并更新版本号。 |
CHANGELOG |
增补 2.1 系列版本记录,描述上述功能合入时间点与摘要。 |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -1,4 +1,4 @@ | |||
| const Version = '2026-07-29 23:57:34'; | |||
| const Version = '2026-08-11 14:45:22'; | |||
Comment on lines
766
to
773
| } finally { | ||
| const 保持木马UDP反代下行 = !转发失败 && 首包.isUDP && 首包.协议 === 'trojan' && 木马UDP上下文.反代地址 && 木马UDP上下文.反代Socket; | ||
| 上行写入队列.清空(); | ||
| if (转发失败) 失效远端连接(); | ||
| 释放远端写入器(); | ||
| if (!保持木马UDP反代下行) try { 木马UDP上下文.反代Socket?.close() } catch (e) { } | ||
| try { reader.releaseLock() } catch (e) { } | ||
| const 保持木马UDP反代下行 = !转发失败 && 首包.协议 === 'trojan' && 木马UDP上下文.反代地址 && 木马UDP上下文.反代Socket; | ||
| if (!保持木马UDP反代下行) { | ||
| try { 木马UDP上下文.反代Socket?.close() } catch (e) { } | ||
| closeSocketQuietly(叉桥); | ||
| } | ||
| try { reader.releaseLock() } catch (e) { } | ||
| } |
Comment on lines
+627
to
+631
| try { | ||
| const 响应URL = new URL('https://x.invalid/'); | ||
| 响应URL.searchParams.set(本机Padding键, 生成叉HTTPPadding串(100 + Math.floor(Math.random() * 901))); | ||
| responseHeaders.set(本机Padding头, 响应URL.toString()); | ||
| } catch (e) { } |
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.
PR #1461 · Beta2.1 版本说明
概述 / Summary
本 PR 汇聚自 2026-07-29 以来的 XHTTP 链路优化与混淆能力增强,核心围绕三件事:传输链路重构(降 CPU)、上行数据合包(降开销)、obfs padding 混淆(反检测),并修复一处链式代理解析 Bug。
English: This PR consolidates XHTTP improvements since 07-29: stream-pipe refactor (lower CPU), uplink packet coalescing, XHTTP obfs padding (anti-detection), and a chained-proxy parsing fix.
主要变更 / Changes
1. XHTTP TCP 传输链路重构(性能优化)
request.body.pipeTo(socket.writable)+socket.readable.pipeTo(IdentityTransformStream),移除了旧链路(ReadableStream + 上行写入队列 + BYOB/Grain 逐块搬运),显著降低 CPU 占用。forwardataTCP新增 “仅建立连接”模式:建连并写入首包后直接返回 socket 交由上层 pipe 直通;保留直连失败后自动切换反代的兜底逻辑,gRPC / WS 调用方不受影响。AbortController统一管理上/下行清理,避免连接泄漏。2. XHTTP 上行数据合包机制
创建上行Grain合包流:小块数据先缓冲合包,达到目标字节后统一写入;不足目标字节时由 1ms 定时器自动冲刷。3. XHTTP obfs padding 混淆(反检测增强)
UUID[1:7],键 =_+UUID[25:31]),替代原先基于Referer含x_padding的识别方式,更难被识别为协议特征。获取传输协议配置为 xhttp 输出extra参数(xPaddingObfsMode: true、xPaddingMethod: tokenish、xPaddingPlacement: queryInHeader、xPaddingHeader/Key),客户端开箱即用。4. XHTTP UDP 分支独立
处理XHTTP请求中拆出为独立的处理叉HTTPUDP请求,保留 Trojan UDP 反代 与 DNS 转发逻辑,TCP/UDP 互不影响。5. Bug 修复
/会导致反代配置失效,现已兼容末尾斜杠(/video/xxx/、/trojan=xxx/均可正常解析)。变更明细 / File Changes
_worker.jsCHANGELOG兼容性与风险 / Compatibility & Risk
Referer改为 UUID 派生头/查询键:旧版客户端无 padding 时仍放行,不影响存量用户。相关版本记录 / CHANGELOG
2.1.20260811144522— 优化 XHTTP 上行:数据合包机制(本 PR 主改动)2.1.20260810030901— 新增 XHTTP obfs padding 接收端支持(tokenish / queryInHeader)2.1.20260809231057— 修复 XHTTP 链式代理路径末尾/失效2.1.20260809201158— 优化 XHTTP 传输链路(pipe 直通)、连接管理(仅建立连接模式)、UDP 分支独立