Repository navigation
fix: convert httpupgrade share links to ws with v2ray-http-upgrade - #3415
Merged
Merged
Conversation
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.
Summary
Converting a
vless://link withtype=httpupgrade(or a base64vmess://link with"net":"httpupgrade") producesnetwork: httpupgradeand aws-optswithoutv2ray-http-upgrade. The outbounds only know HTTPUpgrade as a mode of thewstransport, so such a proxy silently falls back to plain TCP and never sends the upgrade request. Addingeddoes not help: it only setsv2ray-http-upgrade-fast-open, which has no effect withoutv2ray-http-upgrade.Fixes #2609
Root cause
The converter writes the link's
typeasnetworkunchanged —mihomo/common/convert/v.go
Line 77 in f1f640b
ws/httpupgradebranch buildsws-optsbut sets nothing that selects HTTPUpgrade, apart from fast-open whenedis present —mihomo/common/convert/v.go
Lines 110 to 135 in f1f640b
The base64 VMess parser has the same branch —
mihomo/common/convert/converter.go
Line 316 in f1f640b
mihomo/common/convert/converter.go
Lines 356 to 390 in f1f640b
The outbounds handle only
network: wsand read the mode fromws-opts.v2ray-http-upgrade—mihomo/adapter/outbound/vless.go
Lines 156 to 166 in f1f640b
The trojan link parser has only a
wscase, sotype=httpupgradethere also ends up asnetwork: httpupgradewithoutws-opts—mihomo/common/convert/converter.go
Lines 186 to 202 in f1f640b
Change
common/convert/v.go(vless): forhttpupgrade, setnetwork: wsandws-opts.v2ray-http-upgrade: true. Path, Host and the existinged→v2ray-http-upgrade-fast-openhandling are kept.common/convert/converter.go(base64 vmess): the same.common/convert/converter.go(trojan): accepthttpupgradein thewscase and set the same two fields.wslinks are not affected.Tests
New tests in
common/convert/converter_test.go:TestConvertsV2RayVlessHTTPUpgrade: link without and withed. Checksnetwork: ws,v2ray-http-upgrade: true, path and Host, fast-open only withed, nomax-early-data, and thatadapter.ParseProxyaccepts the result.TestConvertsV2RayVmessBase64HTTPUpgrade: the same for base64 VMess, withedin the path query (it is removed from the path as before).TestConvertsV2RayTrojanHTTPUpgrade:network: wsandv2ray-http-upgrade: truefor a trojan link.TestConvertsV2RayVlessWSNotHTTPUpgrade: awslink withedstill getsmax-early-dataand nov2ray-http-upgrade.Before the fix the three HTTPUpgrade tests fail (
networkishttpupgrade,v2ray-http-upgradeis missing). After the fix all tests in the package pass.I also checked the wire behaviour with a throwaway test (not included). The converted vless proxy dialed a loopback listener. Before the fix the listener never received an HTTP request; reading one timed out. After the fix it got
GET /upwithUpgrade: websocket, noSec-WebSocket-Key, andHost: cdn.example.com.go test ./common/convert/(with and without-tags with_gvisor),go vet ./common/convert/andgofmt -lare clean (Go 1.26, linux/amd64).Limitations
The trojan parser still does not read
hostoredforws/httpupgrade. That is how it already behaves forws, and I left it unchanged here.