mirror of
https://github.com/alireza0/s-ui.git
synced 2026-11-18 06:03:15 +00:00
sub: keep max_early_data in Clash ws options (#1335)
* sub: keep max_early_data in Clash ws options The Clash output copied early_data_header_name but not max_early_data, so Clash clients never sent early data. * sub: read max_early_data the way link generation does
This commit is contained in:
parent
7f5284843d
commit
3d312ddcd9
2 changed files with 42 additions and 0 deletions
|
|
@ -351,6 +351,10 @@ func (s *ClashService) ConvertToClashMeta(outbounds *[]map[string]interface{}, b
|
|||
if ed, ok := transport["early_data_header_name"].(string); ok {
|
||||
wsOpts["early-data-header-name"] = ed
|
||||
}
|
||||
// Without max-early-data the client ignores the header name.
|
||||
if maxED, ok := transport["max_early_data"].(float64); ok && maxED > 0 {
|
||||
wsOpts["max-early-data"] = int(maxED)
|
||||
}
|
||||
if tt == "httpupgrade" {
|
||||
wsOpts["v2ray-http-upgrade"] = true
|
||||
}
|
||||
|
|
|
|||
38
sub/clash_early_data_test.go
Normal file
38
sub/clash_early_data_test.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package sub
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestClashWsKeepsMaxEarlyData(t *testing.T) {
|
||||
openClashTestSettings(t)
|
||||
var outbound map[string]interface{}
|
||||
err := json.Unmarshal([]byte(`{"type": "vless", "tag": "ws", "server": "192.0.2.1", "server_port": 443, "uuid": "00000000-0000-4000-8000-000000000001", "tls": {"enabled": true, "server_name": "ws.example"}, "transport": {"type": "ws", "path": "/socket", "max_early_data": 2048, "early_data_header_name": "Sec-WebSocket-Protocol"}}`), &outbound)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outbounds := []map[string]interface{}{outbound}
|
||||
result, err := (&ClashService{}).ConvertToClashMeta(&outbounds, "mode: rule\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var config struct {
|
||||
Proxies []map[string]interface{} `yaml:"proxies"`
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(result), &config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(config.Proxies) != 1 {
|
||||
t.Fatalf("got %d proxies, want one", len(config.Proxies))
|
||||
}
|
||||
wsOpts, _ := config.Proxies[0]["ws-opts"].(map[string]interface{})
|
||||
if wsOpts["max-early-data"] != 2048 {
|
||||
t.Errorf("max-early-data = %v, want 2048", wsOpts["max-early-data"])
|
||||
}
|
||||
if wsOpts["early-data-header-name"] != "Sec-WebSocket-Protocol" {
|
||||
t.Errorf("early-data-header-name = %v", wsOpts["early-data-header-name"])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue