Skip to content

Commit

Permalink
Add xhttp extra for xray
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Nov 14, 2024
1 parent 59b7daa commit b8a0293
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 56 deletions.
1 change: 1 addition & 0 deletions v2rayN/ServiceLib/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public static async Task<int> AddServer(Config config, ProfileItem profileItem)
item.PublicKey = profileItem.PublicKey;
item.ShortId = profileItem.ShortId;
item.SpiderX = profileItem.SpiderX;
item.Extra = profileItem.Extra;
}

var ret = item.ConfigType switch
Expand Down
5 changes: 5 additions & 0 deletions v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref
{
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
}
if (Utils.IsNotEmpty(item.Extra))
{
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
}
break;

case nameof(ETransport.http):
Expand Down Expand Up @@ -180,6 +184,7 @@ protected static int ResolveStdTransport(NameValueCollection query, ref ProfileI
item.RequestHost = Utils.UrlDecode(query["host"] ?? "");
item.Path = Utils.UrlDecode(query["path"] ?? "/");
item.HeaderType = Utils.UrlDecode(query["mode"] ?? "");
item.Extra = Utils.UrlDecode(query["extra"] ?? "");
break;

case nameof(ETransport.http):
Expand Down
44 changes: 13 additions & 31 deletions v2rayN/ServiceLib/Models/ProfileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,25 @@ public ProfileItem()

public string GetSummary()
{
string summary = string.Format("[{0}] ", (ConfigType).ToString());
string[] arrAddr = Address.Split('.');
string addr;
if (arrAddr.Length > 2)
var summary = $"[{(ConfigType).ToString()}] ";
var arrAddr = Address.Split('.');
var addr = arrAddr.Length switch
{
addr = $"{arrAddr.First()}***{arrAddr.Last()}";
}
else if (arrAddr.Length > 1)
{
addr = $"***{arrAddr.Last()}";
}
else
> 2 => $"{arrAddr.First()}***{arrAddr.Last()}",
> 1 => $"***{arrAddr.Last()}",
_ => Address
};
summary += ConfigType switch
{
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;
}
EConfigType.Custom => $"[{CoreType.ToString()}]{Remarks}",
_ => $"{Remarks}({addr}:{Port})"
};
return summary;
}

public List<string>? GetAlpn()
{
if (Utils.IsNullOrEmpty(Alpn))
{
return null;
}
else
{
return Utils.String2List(Alpn);
}
return Utils.IsNullOrEmpty(Alpn) ? null : Utils.String2List(Alpn);
}

public string GetNetwork()
Expand Down Expand Up @@ -110,5 +91,6 @@ public string GetNetwork()
public string PublicKey { get; set; }
public string ShortId { get; set; }
public string SpiderX { get; set; }
public string Extra { get; set; }
}
}
1 change: 1 addition & 0 deletions v2rayN/ServiceLib/Models/V2rayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public class XhttpSettings4Ray
public string? scMaxConcurrentPosts { get; set; }
public string? scMinPostsIntervalMs { get; set; }
public Xmux4Ray? xmux { get; set; }
public object? extra { get; set; }
}

public class Xmux4Ray
Expand Down
9 changes: 9 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,4 +1384,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp mode</value>
</data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra raw JSON, format: { XHTTPObject }</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,4 +1384,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp mode</value>
</data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra raw JSON, format: { XHTTPObject }</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,4 +1384,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp mode</value>
</data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra raw JSON, format: { XHTTPObject }</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1381,4 +1381,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp 模式</value>
</data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra 原始 JSON,格式: { XHTTPObject }</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1381,4 +1381,7 @@
<data name="TransportHeaderTypeTip5" xml:space="preserve">
<value>*xhttp 模式</value>
</data>
<data name="TransportExtraTip" xml:space="preserve">
<value>XHTTP Extra 原始 JSON,格式: { XHTTPObject }</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ public async Task<int> GenBoundStreamSettings(ProfileItem node, StreamSettings4R
{
xhttpSettings.mode = node.HeaderType;
}
if (Utils.IsNotEmpty(node.Extra))
{
xhttpSettings.extra = JsonUtils.ParseJson(node.Extra);
}

streamSettings.xhttpSettings = xhttpSettings;

Expand Down
60 changes: 49 additions & 11 deletions v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
x:Name="txtPort"
Grid.Row="3"
Grid.Column="1"
Width="100"
Width="200"
HorizontalAlignment="Left"
Classes="Margin8" />
</Grid>
Expand Down Expand Up @@ -164,7 +164,7 @@
x:Name="txtAlterId"
Grid.Row="2"
Grid.Column="1"
Width="100"
Width="200"
HorizontalAlignment="Left"
Classes="Margin8" />

Expand Down Expand Up @@ -458,7 +458,7 @@
x:Name="cmbHeaderType8"
Grid.Row="3"
Grid.Column="1"
Width="100"
Width="200"
Classes="Margin8" />
</Grid>
<Grid
Expand Down Expand Up @@ -541,7 +541,7 @@
x:Name="txtShortId9"
Grid.Row="5"
Grid.Column="1"
Width="100"
Width="200"
HorizontalAlignment="Left"
Classes="Margin8" />
</Grid>
Expand Down Expand Up @@ -584,7 +584,7 @@
x:Name="cmbNetwork"
Grid.Row="1"
Grid.Column="1"
Width="100"
Width="200"
Classes="Margin8" />
<TextBlock
Grid.Row="1"
Expand All @@ -600,12 +600,50 @@
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.TbHeaderType}" />
<ComboBox
x:Name="cmbHeaderType"
<StackPanel
Grid.Row="2"
Grid.Column="1"
Width="100"
Classes="Margin8" />
VerticalAlignment="Center"
Orientation="Horizontal">
<ComboBox
x:Name="cmbHeaderType"
Width="200"
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
x:Name="tipHeaderType"
Grid.Row="2"
Expand Down Expand Up @@ -680,7 +718,7 @@
x:Name="cmbStreamSecurity"
Grid.Row="0"
Grid.Column="1"
Width="100"
Width="200"
Classes="Margin8" />
</Grid>
<Grid
Expand Down Expand Up @@ -749,7 +787,7 @@
x:Name="cmbAllowInsecure"
Grid.Row="4"
Grid.Column="1"
Width="100"
Width="200"
Classes="Margin8" />
</Grid>
<Grid
Expand Down
5 changes: 4 additions & 1 deletion v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public AddServerWindow(ProfileItem profileItem)
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.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.Sni, v => v.txtSNI.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.AllowInsecure, v => v.cmbAllowInsecure.SelectedValue).DisposeWith(disposables);
Expand Down Expand Up @@ -326,6 +327,7 @@ private void SetTips()
network = Global.DefaultNetwork;
}
labHeaderType.IsVisible = true;
btnExtra.IsVisible = false;
tipRequestHost.Text =
tipPath.Text =
tipHeaderType.Text = string.Empty;
Expand Down Expand Up @@ -354,6 +356,7 @@ private void SetTips()
tipPath.Text = ResUI.TransportPathTip1;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip5;
labHeaderType.IsVisible = false;
btnExtra.IsVisible = true;
break;

case nameof(ETransport.h2):
Expand Down
Loading

0 comments on commit b8a0293

Please sign in to comment.