feat: convert support new xhttp-opts fields (#2734)

This commit is contained in:
legiz-ru
2026-04-20 02:49:16 +03:00
committed by GitHub
parent e1bdfba0fb
commit a84724665e
+152 -18
View File
@@ -186,6 +186,9 @@ func parseXHTTPExtra(extra map[string]any, opts map[string]any) {
set("cMaxReuseTimes", "c-max-reuse-times")
set("hMaxRequestTimes", "h-max-request-times")
set("hMaxReusableSecs", "h-max-reusable-secs")
if v, ok := xmux["hKeepAlivePeriod"].(float64); ok {
reuse["h-keep-alive-period"] = int(v)
}
return reuse
}
@@ -196,14 +199,74 @@ func parseXHTTPExtra(extra map[string]any, opts map[string]any) {
if v, ok := extra["xPaddingBytes"].(string); ok && v != "" {
opts["x-padding-bytes"] = v
}
if v, ok := extra["xPaddingObfsMode"].(bool); ok {
opts["x-padding-obfs-mode"] = v
}
if v, ok := extra["xPaddingKey"].(string); ok && v != "" {
opts["x-padding-key"] = v
}
if v, ok := extra["xPaddingHeader"].(string); ok && v != "" {
opts["x-padding-header"] = v
}
if v, ok := extra["xPaddingPlacement"].(string); ok && v != "" {
opts["x-padding-placement"] = v
}
if v, ok := extra["xPaddingMethod"].(string); ok && v != "" {
opts["x-padding-method"] = v
}
if v, ok := extra["uplinkHttpMethod"].(string); ok && v != "" {
opts["uplink-http-method"] = v
}
if v, ok := extra["sessionPlacement"].(string); ok && v != "" {
opts["session-placement"] = v
}
if v, ok := extra["sessionKey"].(string); ok && v != "" {
opts["session-key"] = v
}
if v, ok := extra["seqPlacement"].(string); ok && v != "" {
opts["seq-placement"] = v
}
if v, ok := extra["seqKey"].(string); ok && v != "" {
opts["seq-key"] = v
}
if v, ok := extra["uplinkDataPlacement"].(string); ok && v != "" {
opts["uplink-data-placement"] = v
}
if v, ok := extra["uplinkDataKey"].(string); ok && v != "" {
opts["uplink-data-key"] = v
}
if v, ok := extra["uplinkChunkSize"].(float64); ok {
opts["uplink-chunk-size"] = int(v)
}
if v, ok := extra["scMaxEachPostBytes"].(float64); ok {
opts["sc-max-each-post-bytes"] = int(v)
}
if v, ok := extra["scMinPostsIntervalMs"].(float64); ok {
opts["sc-min-posts-interval-ms"] = int(v)
}
// xmux in root extra → reuse-settings
if xmuxAny, ok := extra["xmux"].(map[string]any); ok && len(xmuxAny) > 0 {
if reuse := xmuxToReuse(xmuxAny); len(reuse) > 0 {
opts["reuse-settings"] = reuse
}
}
if dsAny, ok := extra["downloadSettings"].(map[string]any); ok {
ds := make(map[string]any)
@@ -215,26 +278,49 @@ func parseXHTTPExtra(extra map[string]any, opts map[string]any) {
ds["port"] = int(port)
}
if sec, ok := dsAny["security"].(string); ok && strings.ToLower(sec) == "tls" {
ds["tls"] = true
sec := ""
if s, ok := dsAny["security"].(string); ok {
sec = strings.ToLower(s)
}
if tlsAny, ok := dsAny["tlsSettings"].(map[string]any); ok {
if sn, ok := tlsAny["serverName"].(string); ok && sn != "" {
ds["servername"] = sn
}
if fp, ok := tlsAny["fingerprint"].(string); ok && fp != "" {
ds["client-fingerprint"] = fp
}
if alpnAny, ok := tlsAny["alpn"].([]any); ok && len(alpnAny) > 0 {
alpnList := make([]string, 0, len(alpnAny))
for _, a := range alpnAny {
if s, ok := a.(string); ok {
alpnList = append(alpnList, s)
if sec == "tls" || sec == "reality" {
ds["tls"] = true
if tlsAny, ok := dsAny["tlsSettings"].(map[string]any); ok {
if sn, ok := tlsAny["serverName"].(string); ok && sn != "" {
ds["servername"] = sn
}
if fp, ok := tlsAny["fingerprint"].(string); ok && fp != "" {
ds["client-fingerprint"] = fp
}
if alpnAny, ok := tlsAny["alpn"].([]any); ok && len(alpnAny) > 0 {
alpnList := make([]string, 0, len(alpnAny))
for _, a := range alpnAny {
if s, ok := a.(string); ok {
alpnList = append(alpnList, s)
}
}
if len(alpnList) > 0 {
ds["alpn"] = alpnList
}
}
if len(alpnList) > 0 {
ds["alpn"] = alpnList
if v, ok := tlsAny["allowInsecure"].(bool); ok && v {
ds["skip-cert-verify"] = true
}
}
if sec == "reality" {
if realityAny, ok := dsAny["realitySettings"].(map[string]any); ok {
realityOpts := make(map[string]any)
if pk, ok := realityAny["publicKey"].(string); ok && pk != "" {
realityOpts["public-key"] = pk
}
if sid, ok := realityAny["shortId"].(string); ok && sid != "" {
realityOpts["short-id"] = sid
}
if len(realityOpts) > 0 {
ds["reality-opts"] = realityOpts
}
}
}
}
@@ -246,12 +332,60 @@ func parseXHTTPExtra(extra map[string]any, opts map[string]any) {
if host, ok := xhttpAny["host"].(string); ok && host != "" {
ds["host"] = host
}
if headers, ok := xhttpAny["headers"].(map[string]any); ok && len(headers) > 0 {
ds["headers"] = headers
}
if v, ok := xhttpAny["noGRPCHeader"].(bool); ok && v {
ds["no-grpc-header"] = true
}
if v, ok := xhttpAny["xPaddingBytes"].(string); ok && v != "" {
ds["x-padding-bytes"] = v
}
if v, ok := xhttpAny["xPaddingObfsMode"].(bool); ok {
ds["x-padding-obfs-mode"] = v
}
if v, ok := xhttpAny["xPaddingKey"].(string); ok && v != "" {
ds["x-padding-key"] = v
}
if v, ok := xhttpAny["xPaddingHeader"].(string); ok && v != "" {
ds["x-padding-header"] = v
}
if v, ok := xhttpAny["xPaddingPlacement"].(string); ok && v != "" {
ds["x-padding-placement"] = v
}
if v, ok := xhttpAny["xPaddingMethod"].(string); ok && v != "" {
ds["x-padding-method"] = v
}
if v, ok := xhttpAny["uplinkHttpMethod"].(string); ok && v != "" {
ds["uplink-http-method"] = v
}
if v, ok := xhttpAny["sessionPlacement"].(string); ok && v != "" {
ds["session-placement"] = v
}
if v, ok := xhttpAny["sessionKey"].(string); ok && v != "" {
ds["session-key"] = v
}
if v, ok := xhttpAny["seqPlacement"].(string); ok && v != "" {
ds["seq-placement"] = v
}
if v, ok := xhttpAny["seqKey"].(string); ok && v != "" {
ds["seq-key"] = v
}
if v, ok := xhttpAny["uplinkDataPlacement"].(string); ok && v != "" {
ds["uplink-data-placement"] = v
}
if v, ok := xhttpAny["uplinkDataKey"].(string); ok && v != "" {
ds["uplink-data-key"] = v
}
if v, ok := xhttpAny["uplinkChunkSize"].(float64); ok {
ds["uplink-chunk-size"] = int(v)
}
if v, ok := xhttpAny["scMaxEachPostBytes"].(float64); ok {
ds["sc-max-each-post-bytes"] = int(v)
}
if v, ok := xhttpAny["scMinPostsIntervalMs"].(float64); ok {
ds["sc-min-posts-interval-ms"] = int(v)
}
// xmux inside downloadSettings.xhttpSettings.extra → download-settings.reuse-settings
if dsExtraAny, ok := xhttpAny["extra"].(map[string]any); ok {