From f59bbc9981bc60f4f8fb56c978f2564642e4e9a7 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Sat, 23 Mar 2024 18:26:44 +0800
Subject: [PATCH] Add authority for grpc
---
v2rayN/v2rayN/Handler/CoreConfigV2ray.cs | 23 +++++++++++----------
v2rayN/v2rayN/Handler/ShareHandler.cs | 4 +++-
v2rayN/v2rayN/Model/V2rayConfig.cs | 3 ++-
v2rayN/v2rayN/Resx/ResUI.Designer.cs | 9 ++++++++
v2rayN/v2rayN/Resx/ResUI.resx | 3 +++
v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 3 +++
v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx | 3 +++
v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 1 +
8 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs
index 93db1bc9..e882078c 100644
--- a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs
+++ b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs
@@ -533,11 +533,11 @@ namespace v2rayN.Handler
alpn = node.GetAlpn(),
fingerprint = node.fingerprint.IsNullOrEmpty() ? _config.coreBasicItem.defFingerprint : node.fingerprint
};
- if (!string.IsNullOrWhiteSpace(sni))
+ if (!Utile.IsNullOrEmpty(sni))
{
tlsSettings.serverName = sni;
}
- else if (!string.IsNullOrWhiteSpace(host))
+ else if (!Utile.IsNullOrEmpty(host))
{
tlsSettings.serverName = Utile.String2List(host)[0];
}
@@ -592,15 +592,15 @@ namespace v2rayN.Handler
WsSettings4Ray wsSettings = new();
wsSettings.headers = new Headers4Ray();
string path = node.path;
- if (!string.IsNullOrWhiteSpace(host))
+ if (!Utile.IsNullOrEmpty(host))
{
wsSettings.headers.Host = host;
}
- if (!string.IsNullOrWhiteSpace(path))
+ if (!Utile.IsNullOrEmpty(path))
{
wsSettings.path = path;
}
- if (!string.IsNullOrWhiteSpace(useragent))
+ if (!Utile.IsNullOrEmpty(useragent))
{
wsSettings.headers.UserAgent = useragent;
}
@@ -611,11 +611,11 @@ namespace v2rayN.Handler
case nameof(ETransport.httpupgrade):
HttpupgradeSettings4Ray httpupgradeSettings = new();
- if (!string.IsNullOrWhiteSpace(node.path))
+ if (!Utile.IsNullOrEmpty(node.path))
{
httpupgradeSettings.path = node.path;
}
- if (!string.IsNullOrWhiteSpace(host))
+ if (!Utile.IsNullOrEmpty(host))
{
httpupgradeSettings.host = host;
}
@@ -626,7 +626,7 @@ namespace v2rayN.Handler
case nameof(ETransport.h2):
HttpSettings4Ray httpSettings = new();
- if (!string.IsNullOrWhiteSpace(host))
+ if (!Utile.IsNullOrEmpty(host))
{
httpSettings.host = Utile.String2List(host);
}
@@ -649,7 +649,7 @@ namespace v2rayN.Handler
streamSettings.quicSettings = quicsettings;
if (node.streamSecurity == Global.StreamSecurity)
{
- if (!string.IsNullOrWhiteSpace(sni))
+ if (!Utile.IsNullOrEmpty(sni))
{
streamSettings.tlsSettings.serverName = sni;
}
@@ -663,6 +663,7 @@ namespace v2rayN.Handler
case nameof(ETransport.grpc):
GrpcSettings4Ray grpcSettings = new()
{
+ authority = Utile.IsNullOrEmpty(host) ? null : host,
serviceName = node.path,
multiMode = (node.headerType == Global.GrpcMultiMode),
idle_timeout = _config.grpcItem.idle_timeout,
@@ -721,13 +722,13 @@ namespace v2rayN.Handler
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray);
var normalDNS = item?.normalDNS;
var domainStrategy4Freedom = item?.domainStrategy4Freedom;
- if (string.IsNullOrWhiteSpace(normalDNS))
+ if (Utile.IsNullOrEmpty(normalDNS))
{
normalDNS = "1.1.1.1,8.8.8.8";
}
//Outbound Freedom domainStrategy
- if (!string.IsNullOrWhiteSpace(domainStrategy4Freedom))
+ if (!Utile.IsNullOrEmpty(domainStrategy4Freedom))
{
var outbound = v2rayConfig.outbounds[1];
outbound.settings.domainStrategy = domainStrategy4Freedom;
diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs
index 1a3d85c1..ee41d262 100644
--- a/v2rayN/v2rayN/Handler/ShareHandler.cs
+++ b/v2rayN/v2rayN/Handler/ShareHandler.cs
@@ -364,6 +364,7 @@ namespace v2rayN.Handler
case nameof(ETransport.grpc):
if (!Utile.IsNullOrEmpty(item.path))
{
+ dicQuery.Add("authority", Utile.UrlEncode(item.requestHost));
dicQuery.Add("serviceName", Utile.UrlEncode(item.path));
if (item.headerType is Global.GrpcGunMode or Global.GrpcMultiMode)
{
@@ -592,7 +593,7 @@ namespace v2rayN.Handler
break;
default:
- if (!string.IsNullOrWhiteSpace(i.streamSecurity))
+ if (!Utile.IsNullOrEmpty(i.streamSecurity))
return null;
break;
}
@@ -981,6 +982,7 @@ namespace v2rayN.Handler
break;
case nameof(ETransport.grpc):
+ item.requestHost = Utile.UrlDecode(query["authority"] ?? "");
item.path = Utile.UrlDecode(query["serviceName"] ?? "");
item.headerType = Utile.UrlDecode(query["mode"] ?? Global.GrpcGunMode);
break;
diff --git a/v2rayN/v2rayN/Model/V2rayConfig.cs b/v2rayN/v2rayN/Model/V2rayConfig.cs
index e7927eed..b99e2d71 100644
--- a/v2rayN/v2rayN/Model/V2rayConfig.cs
+++ b/v2rayN/v2rayN/Model/V2rayConfig.cs
@@ -639,7 +639,8 @@ namespace v2rayN.Model
public class GrpcSettings4Ray
{
- public string serviceName { get; set; }
+ public string? authority { get; set; }
+ public string? serviceName { get; set; }
public bool multiMode { get; set; }
public int idle_timeout { get; set; }
public int health_check_timeout { get; set; }
diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs
index 46b792cf..10c8a1de 100644
--- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs
+++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs
@@ -3283,6 +3283,15 @@ namespace v2rayN.Resx {
}
}
+ ///
+ /// 查找类似 *grpc Authority 的本地化字符串。
+ ///
+ public static string TransportRequestHostTip5 {
+ get {
+ return ResourceManager.GetString("TransportRequestHostTip5", resourceCulture);
+ }
+ }
+
///
/// 查找类似 Ungrouped 的本地化字符串。
///
diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx
index 12cdb236..78eeb13f 100644
--- a/v2rayN/v2rayN/Resx/ResUI.resx
+++ b/v2rayN/v2rayN/Resx/ResUI.resx
@@ -1195,4 +1195,7 @@
Test terminating...
+
+ *grpc Authority
+
\ No newline at end of file
diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
index c694f7f2..b53aa46f 100644
--- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
+++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
@@ -1192,4 +1192,7 @@
测试终止中...
+
+ *grpc Authority
+
\ No newline at end of file
diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
index 8b3e6ac2..6e6ff80e 100644
--- a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
+++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
@@ -1165,4 +1165,7 @@
測試終止中...
+
+ *grpc Authority
+
\ No newline at end of file
diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs
index e79b2db3..6e0f5f86 100644
--- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs
+++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs
@@ -346,6 +346,7 @@ namespace v2rayN.Views
break;
case nameof(ETransport.grpc):
+ tipRequestHost.Text = ResUI.TransportRequestHostTip5;
tipPath.Text = ResUI.TransportPathTip4;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip4;
labHeaderType.Visibility = Visibility.Hidden;