diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index ac6d637e9..ddd5d7d59 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -1521,3 +1521,13 @@ function get_core(field, candidates) end return nil end + +function cleanEmptyTables(t) + if type(t) ~= "table" then return nil end + for k, v in pairs(t) do + if type(v) == "table" then + t[k] = cleanEmptyTables(v) + end + end + return next(t) and t or nil +end diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index 9bcacff2f..4585f66cd 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -241,31 +241,21 @@ function gen_outbound(flag, node, tag, proxy_table) path = node.xhttp_path or "/", host = node.xhttp_host, extra = (function() - local extra_tbl = {} - -- 解析 xhttp_extra 并做简单容错处理 + local extra = {} if node.xhttp_extra then - local success, parsed = pcall(jsonc.parse, api.base64Decode(node.xhttp_extra)) - if success and parsed then - extra_tbl = parsed.extra or parsed - for k, v in pairs(extra_tbl) do - if (type(v) == "table" and next(v) == nil) or v == nil then - extra_tbl[k] = nil - end - end + local ok, parsed = pcall(jsonc.parse, api.base64Decode(node.xhttp_extra)) + if ok and type(parsed) == "table" then + extra = parsed.extra or parsed end end -- 处理 User-Agent if node.user_agent and node.user_agent ~= "" then - extra_tbl.headers = extra_tbl.headers or {} - if not extra_tbl.headers["User-Agent"] and not extra_tbl.headers["user-agent"] then - extra_tbl.headers["User-Agent"] = node.user_agent + extra.headers = extra.headers or {} + if not extra.headers["User-Agent"] and not extra.headers["user-agent"] then + extra.headers["User-Agent"] = node.user_agent end end - -- 清理空的 headers - if extra_tbl.headers and next(extra_tbl.headers) == nil then - extra_tbl.headers = nil - end - return next(extra_tbl) ~= nil and extra_tbl or nil + return api.cleanEmptyTables(extra) end)() } or nil, hysteriaSettings = (node.transport == "hysteria") and { @@ -322,25 +312,10 @@ function gen_outbound(flag, node, tag, proxy_table) if node.finalmask and node.finalmask ~= "" then local ok, fm = pcall(jsonc.parse, api.base64Decode(node.finalmask)) if ok and type(fm) == "table" then - if not finalmask or not next(finalmask) then - finalmask = fm - else - if type(fm.udp) == "table" then - finalmask.udp = finalmask.udp or {} - for i = 1, #fm.udp do - finalmask.udp[#finalmask.udp+1] = fm.udp[i] - end - end - if type(fm.tcp) == "table" then - finalmask.tcp = fm.tcp - end - if type(fm.quicParams) == "table" then - finalmask.quicParams = fm.quicParams - end - end + finalmask = fm end end - return (finalmask and next(finalmask)) and finalmask or nil + return api.cleanEmptyTables(finalmask) end)() } or nil, settings = { @@ -649,25 +624,10 @@ function gen_config_server(node) if node.finalmask and node.finalmask ~= "" then local ok, fm = pcall(jsonc.parse, api.base64Decode(node.finalmask)) if ok and type(fm) == "table" then - if not finalmask or not next(finalmask) then - finalmask = fm - else - if type(fm.udp) == "table" then - finalmask.udp = finalmask.udp or {} - for i = 1, #fm.udp do - finalmask.udp[#finalmask.udp+1] = fm.udp[i] - end - end - if type(fm.tcp) == "table" then - finalmask.tcp = fm.tcp - end - if type(fm.quicParams) == "table" then - finalmask.quicParams = fm.quicParams - end - end + finalmask = fm end end - return (finalmask and next(finalmask)) and finalmask or nil + return api.cleanEmptyTables(finalmask) end)(), sockopt = { tcpFastOpen = (node.tcp_fast_open == "1") and true or nil,