Add xhttp extra for xray

https://github.com/XTLS/Xray-core/pull/4000
This commit is contained in:
2dust 2024-11-14 14:37:03 +08:00
parent 59b7daaef5
commit b8a0293b52
15 changed files with 151 additions and 56 deletions

View file

@ -240,6 +240,7 @@ namespace ServiceLib.Handler
item.PublicKey = profileItem.PublicKey; item.PublicKey = profileItem.PublicKey;
item.ShortId = profileItem.ShortId; item.ShortId = profileItem.ShortId;
item.SpiderX = profileItem.SpiderX; item.SpiderX = profileItem.SpiderX;
item.Extra = profileItem.Extra;
} }
var ret = item.ConfigType switch var ret = item.ConfigType switch

View file

@ -107,6 +107,10 @@ namespace ServiceLib.Handler.Fmt
{ {
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType)); dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
} }
if (Utils.IsNotEmpty(item.Extra))
{
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
}
break; break;
case nameof(ETransport.http): case nameof(ETransport.http):
@ -180,6 +184,7 @@ namespace ServiceLib.Handler.Fmt
item.RequestHost = Utils.UrlDecode(query["host"] ?? ""); item.RequestHost = Utils.UrlDecode(query["host"] ?? "");
item.Path = Utils.UrlDecode(query["path"] ?? "/"); item.Path = Utils.UrlDecode(query["path"] ?? "/");
item.HeaderType = Utils.UrlDecode(query["mode"] ?? ""); item.HeaderType = Utils.UrlDecode(query["mode"] ?? "");
item.Extra = Utils.UrlDecode(query["extra"] ?? "");
break; break;
case nameof(ETransport.http): case nameof(ETransport.http):

View file

@ -30,44 +30,25 @@ namespace ServiceLib.Models
public string GetSummary() public string GetSummary()
{ {
string summary = string.Format("[{0}] ", (ConfigType).ToString()); var summary = $"[{(ConfigType).ToString()}] ";
string[] arrAddr = Address.Split('.'); var arrAddr = Address.Split('.');
string addr; var addr = arrAddr.Length switch
if (arrAddr.Length > 2)
{ {
addr = $"{arrAddr.First()}***{arrAddr.Last()}"; > 2 => $"{arrAddr.First()}***{arrAddr.Last()}",
} > 1 => $"***{arrAddr.Last()}",
else if (arrAddr.Length > 1) _ => Address
};
summary += ConfigType switch
{ {
addr = $"***{arrAddr.Last()}"; EConfigType.Custom => $"[{CoreType.ToString()}]{Remarks}",
} _ => $"{Remarks}({addr}:{Port})"
else };
{
addr = Address;
}
switch (ConfigType)
{
case EConfigType.Custom:
summary += string.Format("[{1}]{0}", Remarks, CoreType.ToString());
break;
default:
summary += string.Format("{0}({1}:{2})", Remarks, addr, Port);
break;
}
return summary; return summary;
} }
public List<string>? GetAlpn() public List<string>? GetAlpn()
{ {
if (Utils.IsNullOrEmpty(Alpn)) return Utils.IsNullOrEmpty(Alpn) ? null : Utils.String2List(Alpn);
{
return null;
}
else
{
return Utils.String2List(Alpn);
}
} }
public string GetNetwork() public string GetNetwork()
@ -110,5 +91,6 @@ namespace ServiceLib.Models
public string PublicKey { get; set; } public string PublicKey { get; set; }
public string ShortId { get; set; } public string ShortId { get; set; }
public string SpiderX { get; set; } public string SpiderX { get; set; }
public string Extra { get; set; }
} }
} }

View file

@ -353,6 +353,7 @@ namespace ServiceLib.Models
public string? scMaxConcurrentPosts { get; set; } public string? scMaxConcurrentPosts { get; set; }
public string? scMinPostsIntervalMs { get; set; } public string? scMinPostsIntervalMs { get; set; }
public Xmux4Ray? xmux { get; set; } public Xmux4Ray? xmux { get; set; }
public object? extra { get; set; }
} }
public class Xmux4Ray public class Xmux4Ray

View file

@ -3697,6 +3697,15 @@ namespace ServiceLib.Resx {
} }
} }
/// <summary>
/// 查找类似 XHTTP Extra raw JSON, format: { XHTTPObject } 的本地化字符串。
/// </summary>
public static string TransportExtraTip {
get {
return ResourceManager.GetString("TransportExtraTip", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 *tcp camouflage type 的本地化字符串。 /// 查找类似 *tcp camouflage type 的本地化字符串。
/// </summary> /// </summary>

View file

@ -1384,4 +1384,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve"> <data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp mode</value> <value>*xhttp mode</value>
</data> </data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra raw JSON, format: { XHTTPObject }</value>
</data>
</root> </root>

View file

@ -1384,4 +1384,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve"> <data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp mode</value> <value>*xhttp mode</value>
</data> </data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra raw JSON, format: { XHTTPObject }</value>
</data>
</root> </root>

View file

@ -1384,4 +1384,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve"> <data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp mode</value> <value>*xhttp mode</value>
</data> </data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra raw JSON, format: { XHTTPObject }</value>
</data>
</root> </root>

View file

@ -1381,4 +1381,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve"> <data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp 模式</value> <value>*xhttp 模式</value>
</data> </data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra 原始 JSON格式 { XHTTPObject }</value>
</data>
</root> </root>

View file

@ -1381,4 +1381,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve"> <data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp 模式</value> <value>*xhttp 模式</value>
</data> </data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra 原始 JSON格式 { XHTTPObject }</value>
</data>
</root> </root>

View file

@ -949,6 +949,10 @@ namespace ServiceLib.Services.CoreConfig
{ {
xhttpSettings.mode = node.HeaderType; xhttpSettings.mode = node.HeaderType;
} }
if (Utils.IsNotEmpty(node.Extra))
{
xhttpSettings.extra = JsonUtils.ParseJson(node.Extra);
}
streamSettings.xhttpSettings = xhttpSettings; streamSettings.xhttpSettings = xhttpSettings;

View file

@ -112,7 +112,7 @@
x:Name="txtPort" x:Name="txtPort"
Grid.Row="3" Grid.Row="3"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Classes="Margin8" /> Classes="Margin8" />
</Grid> </Grid>
@ -164,7 +164,7 @@
x:Name="txtAlterId" x:Name="txtAlterId"
Grid.Row="2" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Classes="Margin8" /> Classes="Margin8" />
@ -458,7 +458,7 @@
x:Name="cmbHeaderType8" x:Name="cmbHeaderType8"
Grid.Row="3" Grid.Row="3"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Classes="Margin8" /> Classes="Margin8" />
</Grid> </Grid>
<Grid <Grid
@ -541,7 +541,7 @@
x:Name="txtShortId9" x:Name="txtShortId9"
Grid.Row="5" Grid.Row="5"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Classes="Margin8" /> Classes="Margin8" />
</Grid> </Grid>
@ -584,7 +584,7 @@
x:Name="cmbNetwork" x:Name="cmbNetwork"
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Classes="Margin8" /> Classes="Margin8" />
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
@ -600,12 +600,50 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Classes="Margin8" Classes="Margin8"
Text="{x:Static resx:ResUI.TbHeaderType}" /> Text="{x:Static resx:ResUI.TbHeaderType}" />
<ComboBox <StackPanel
x:Name="cmbHeaderType"
Grid.Row="2" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
Width="100" VerticalAlignment="Center"
Orientation="Horizontal">
<ComboBox
x:Name="cmbHeaderType"
Width="200"
Classes="Margin8" /> Classes="Margin8" />
<Button
x:Name="btnExtra"
Width="30"
Height="30"
Margin="10,0"
Theme="{DynamicResource BorderlessButton}">
<Button.Content>
<PathIcon
Width="20"
Height="20"
Data="{StaticResource building_more}"
Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel>
<TextBlock
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.TransportExtraTip}" />
<TextBox
x:Name="txtExtra"
Width="400"
MinHeight="100"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Classes="TextArea Margin8"
MinLines="6"
TextWrapping="Wrap" />
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>
<TextBlock <TextBlock
x:Name="tipHeaderType" x:Name="tipHeaderType"
Grid.Row="2" Grid.Row="2"
@ -680,7 +718,7 @@
x:Name="cmbStreamSecurity" x:Name="cmbStreamSecurity"
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Classes="Margin8" /> Classes="Margin8" />
</Grid> </Grid>
<Grid <Grid
@ -749,7 +787,7 @@
x:Name="cmbAllowInsecure" x:Name="cmbAllowInsecure"
Grid.Row="4" Grid.Row="4"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Classes="Margin8" /> Classes="Margin8" />
</Grid> </Grid>
<Grid <Grid

View file

@ -208,6 +208,7 @@ namespace v2rayN.Desktop.Views
this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.RequestHost, v => v.txtRequestHost.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.RequestHost, v => v.txtRequestHost.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Extra, v => v.txtExtra.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables);
@ -326,6 +327,7 @@ namespace v2rayN.Desktop.Views
network = Global.DefaultNetwork; network = Global.DefaultNetwork;
} }
labHeaderType.IsVisible = true; labHeaderType.IsVisible = true;
btnExtra.IsVisible = false;
tipRequestHost.Text = tipRequestHost.Text =
tipPath.Text = tipPath.Text =
tipHeaderType.Text = string.Empty; tipHeaderType.Text = string.Empty;
@ -354,6 +356,7 @@ namespace v2rayN.Desktop.Views
tipPath.Text = ResUI.TransportPathTip1; tipPath.Text = ResUI.TransportPathTip1;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip5; tipHeaderType.Text = ResUI.TransportHeaderTypeTip5;
labHeaderType.IsVisible = false; labHeaderType.IsVisible = false;
btnExtra.IsVisible = true;
break; break;
case nameof(ETransport.h2): case nameof(ETransport.h2):

View file

@ -17,6 +17,13 @@
Style="{StaticResource WindowGlobal}" Style="{StaticResource WindowGlobal}"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
mc:Ignorable="d"> mc:Ignorable="d">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Popupbox.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<DockPanel Margin="{StaticResource Margin8}"> <DockPanel Margin="{StaticResource Margin8}">
<StackPanel <StackPanel
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
@ -128,7 +135,7 @@
x:Name="txtPort" x:Name="txtPort"
Grid.Row="3" Grid.Row="3"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
@ -188,7 +195,7 @@
x:Name="txtAlterId" x:Name="txtAlterId"
Grid.Row="2" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
@ -513,7 +520,7 @@
x:Name="cmbHeaderType8" x:Name="cmbHeaderType8"
Grid.Row="3" Grid.Row="3"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
</Grid> </Grid>
@ -606,7 +613,7 @@
x:Name="txtShortId9" x:Name="txtShortId9"
Grid.Row="5" Grid.Row="5"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
@ -653,7 +660,7 @@
x:Name="cmbNetwork" x:Name="cmbNetwork"
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
<TextBlock <TextBlock
@ -672,13 +679,40 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}" Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbHeaderType}" /> Text="{x:Static resx:ResUI.TbHeaderType}" />
<ComboBox <StackPanel
x:Name="cmbHeaderType"
Grid.Row="2" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
Width="100" VerticalAlignment="Center"
Orientation="Horizontal">
<ComboBox
x:Name="cmbHeaderType"
Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
<materialDesign:PopupBox
x:Name="popExtra"
HorizontalAlignment="Right"
StaysOpen="True"
Style="{StaticResource MaterialDesignToolForegroundPopupBox}">
<StackPanel>
<TextBlock
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TransportExtraTip}" />
<TextBox
x:Name="txtExtra"
Width="400"
Margin="{StaticResource Margin4}"
VerticalAlignment="Top"
AcceptsReturn="True"
MinLines="6"
Style="{StaticResource MyOutlinedTextBox}"
TextWrapping="Wrap" />
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
<TextBlock <TextBlock
x:Name="tipHeaderType" x:Name="tipHeaderType"
Grid.Row="2" Grid.Row="2"
@ -764,7 +798,7 @@
x:Name="cmbStreamSecurity" x:Name="cmbStreamSecurity"
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
</Grid> </Grid>
@ -842,7 +876,7 @@
x:Name="cmbAllowInsecure" x:Name="cmbAllowInsecure"
Grid.Row="4" Grid.Row="4"
Grid.Column="1" Grid.Column="1"
Width="100" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
</Grid> </Grid>

View file

@ -202,6 +202,7 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.RequestHost, v => v.txtRequestHost.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.RequestHost, v => v.txtRequestHost.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Extra, v => v.txtExtra.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables);
@ -321,6 +322,7 @@ namespace v2rayN.Views
network = Global.DefaultNetwork; network = Global.DefaultNetwork;
} }
labHeaderType.Visibility = Visibility.Visible; labHeaderType.Visibility = Visibility.Visible;
popExtra.Visibility = Visibility.Hidden;
tipRequestHost.Text = tipRequestHost.Text =
tipPath.Text = tipPath.Text =
tipHeaderType.Text = string.Empty; tipHeaderType.Text = string.Empty;
@ -349,6 +351,7 @@ namespace v2rayN.Views
tipPath.Text = ResUI.TransportPathTip1; tipPath.Text = ResUI.TransportPathTip1;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip5; tipHeaderType.Text = ResUI.TransportHeaderTypeTip5;
labHeaderType.Visibility = Visibility.Hidden; labHeaderType.Visibility = Visibility.Hidden;
popExtra.Visibility = Visibility.Visible;
break; break;
case nameof(ETransport.h2): case nameof(ETransport.h2):