Conversation
wwqgtxx
reviewed
Mar 14, 2021
| conn, resp, err := dialer.Dial(uri, wsSettings.GetRequestHeader()) | ||
| header := wsSettings.GetRequestHeader() | ||
| if ed != nil { | ||
| header.Set("Sec-WebSocket-Protocol", base64.StdEncoding.EncodeToString(ed)) |
Contributor
There was a problem hiding this comment.
这里的header需不需要clone一次,防止并发dialWebsocket的时候出错?
Member
Author
There was a problem hiding this comment.
Xray-core/transport/internet/websocket/config.go
Lines 23 to 29 in 9dec65e
wwqgtxx
added a commit
to wwqgtxx/wstunnel
that referenced
this pull request
Mar 14, 2021
wwqgtxx
added a commit
to wwqgtxx/wstunnel
that referenced
this pull request
Mar 15, 2021
(be careful with golang's textproto.CanonicalMIMEHeaderKey)
Merged
Member
Author
|
Updates in #421 |
Closed
Merged
it2konst
pushed a commit
to it2konst/gametunnel-core
that referenced
this pull request
Mar 1, 2026
drovosek229
pushed a commit
to drovosek229/Xray-core
that referenced
this pull request
Mar 16, 2026
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.
Background
v2fly/v2ray-core#378 本来想的是不等握手完成就连着发 payload,但某些 WebSocket 服务端实现可能会拒绝此行为
v2fly 的计划是将首个 payload 放 path,我不喜欢那个做法,因为要改很多配置,而且 path 往往会被 log
这里感谢 @darhwa 提出可以把首个 payload 放 WS header v2fly/v2ray-core#378 (comment)
Header
最初的想法是需要自定义 header 名,但有一些麻烦,我希望尽量减少对现有配置的改动,以便此功能可以迅速普及
所以最终决定使用
Sec-WebSocket-Protocol这个 header 承载 early data(一般带着内层 TLS Client Hello):ws = new WebSocket(url [, protocols])设置它,方便日后的浏览器中转具体方式是客户端将 early data 进行标准 Base64 编码后放入这个 header,服务端若成功解析即当作 early data 处理
Configuration
为了此功能可以迅速普及,经过反复思考后,我的设计是不需 GUI 新增配置项,只需在现有 path 后加上
?ed=2048?ed=2048即可减少 1-RTT,2048 代表 early data 的长度上限,目前建议写 2048与此同时,现在就可以下发带
?ed=2048的订阅,因为旧的客户端虽然不支持 early data,但仍然可以正常使用节点?ed=2048在本地就会被解析,不会被发到服务端,到服务端的是Sec-WebSocket-Protocol?ed=2048在本地不会被解析,且会被发到服务端,但只是多了个参数,不会影响正常使用就像 XUDP 一样,这也是一个非常简单且优雅的解决方案。至此,绝大多数场景下,WSS 的延迟已等同于 TCP+TLS 🎉