From dea143b20d33f6b567d99f5587ebaceb9cb00136 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 13 Apr 2026 02:58:40 +0000 Subject: [PATCH] Add sing-box ua (#9087) * Add sing-box ua * Add curl and fix --- v2rayN/ServiceLib/Global.cs | 8 +++++--- v2rayN/ServiceLib/Models/SingboxConfig.cs | 2 ++ v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 2 +- v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.fr.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.hu.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.ru.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 2 +- .../Singbox/SingboxOutboundService.cs | 17 +++++++++++++++++ 11 files changed, 32 insertions(+), 11 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index dd83c77e..7b5ff88a 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -189,7 +189,8 @@ public class Global {"safari","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" }, {"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" }, {"none",""}, - {"golang",""} + {"golang","Go-http-client/1.1"}, + {"curl","curl/7.68.0"}, }; public const string Hysteria2ProtocolShare = "hy2://"; @@ -393,7 +394,8 @@ public class Global "chrome", "firefox", "edge", - "golang" + "curl", + "golang", ]; public static readonly List XhttpMode = @@ -440,7 +442,7 @@ public class Global "https://dns.cloudflare.com/dns-query", "https://doh.dns.sb/dns-query", "https://doh.opendns.com/dns-query", - "https://common.dot.dns.yandex.net", + "https://common.dot.dns.yandex.net/dns-query", "8.8.8.8", "1.1.1.1", "185.222.222.222", diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/SingboxConfig.cs index f2331cc4..000097bb 100644 --- a/v2rayN/ServiceLib/Models/SingboxConfig.cs +++ b/v2rayN/ServiceLib/Models/SingboxConfig.cs @@ -237,6 +237,8 @@ public class Transport4Sbox public class Headers4Sbox { public string? Host { get; set; } + [JsonPropertyName("User-Agent")] + public string UserAgent { get; set; } } public class HyObfs4Sbox diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index c64b7402..d323889a 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3772,7 +3772,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 This parameter is valid only for tcp/http and ws 的本地化字符串。 + /// 查找类似 This parameter is valid only for tcp/http, ws, gRPC and xhttp 的本地化字符串。 /// public static string TbSettingsDefUserAgentTips { get { diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 56e7bd5c..eda45653 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -937,7 +937,7 @@ User-Agent - این پارامتر فقط برای tcp/http و ws معتبر است + This parameter is valid only for tcp/http, ws, gRPC and xhttp FontFamily (نیاز به راه اندازی مجدد) diff --git a/v2rayN/ServiceLib/Resx/ResUI.fr.resx b/v2rayN/ServiceLib/Resx/ResUI.fr.resx index 9e81a7c9..8f173e6e 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fr.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fr.resx @@ -937,7 +937,7 @@ Agent utilisateur (User-Agent) - Valable uniquement pour les protocoles tcp/http et ws + This parameter is valid only for tcp/http, ws, gRPC and xhttp Police actuelle (redémarrage requis) diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 8f64e04b..4437eafa 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -937,7 +937,7 @@ User-Agent - Ez a paraméter csak tcp/http és ws esetén érvényes + This parameter is valid only for tcp/http, ws, gRPC and xhttp Betűtípus (újraindítást igényel) diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 3b21ec73..6bbf3f72 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -937,7 +937,7 @@ User-Agent - This parameter is valid only for tcp/http and ws + This parameter is valid only for tcp/http, ws, gRPC and xhttp Font family (requires restart) diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 86a613c3..c777c4d9 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -937,7 +937,7 @@ User-Agent - Параметр действует только для TCP/HTTP и WebSocket (WS) + This parameter is valid only for tcp/http, ws, gRPC and xhttp Шрифт (требуется перезапуск) diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 36e5efc0..b26059ad 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -937,7 +937,7 @@ 用户代理 (User-Agent) - 仅对 tcp/http、ws 协议生效 + 仅对 tcp/http、ws、gRPC、xhttp 生效 当前字体 (需重启) diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index be707759..bacf2f11 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -937,7 +937,7 @@ 使用者代理 (User-Agent) - 僅對 TCP/HTTP、WS 協定生效 + 僅對 TCP/HTTP、WS、gRPC、XHTTP 生效 目前字型 (需重啟) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index 7a86761f..34a7f49f 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -438,6 +438,8 @@ public partial class CoreConfigSingboxService try { var transport = new Transport4Sbox(); + var useragent = _config.CoreBasicItem.DefUserAgent ?? string.Empty; + var useragentValue = Global.TcpHttpUserAgentTexts.GetValueOrDefault(useragent, useragent); switch (_node.GetNetwork()) { @@ -453,6 +455,11 @@ public partial class CoreConfigSingboxService transport.type = nameof(ETransport.http); transport.host = _node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(_node.RequestHost); transport.path = _node.Path.NullIfEmpty(); + if (!useragentValue.IsNullOrEmpty()) + { + transport.headers ??= new(); + transport.headers.UserAgent = useragentValue; + } } break; @@ -494,12 +501,22 @@ public partial class CoreConfigSingboxService Host = _node.RequestHost }; } + if (!useragentValue.IsNullOrEmpty()) + { + transport.headers ??= new(); + transport.headers.UserAgent = useragentValue; + } break; case nameof(ETransport.httpupgrade): transport.type = nameof(ETransport.httpupgrade); transport.path = _node.Path.NullIfEmpty(); transport.host = _node.RequestHost.NullIfEmpty(); + if (!useragentValue.IsNullOrEmpty()) + { + transport.headers ??= new(); + transport.headers.UserAgent = useragentValue; + } break;