Skip to content

Commit 96cb398

Browse files
author
xboard
committed
fix(stash): correct TCP/HTTP network type handling in node generation
1 parent a90c5c4 commit 96cb398

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

app/Protocols/Stash.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,13 @@ public static function buildVmess($uuid, $server)
251251

252252
switch (data_get($protocol_settings, 'network')) {
253253
case 'tcp':
254-
$array['network'] = data_get($protocol_settings, 'network_settings.header.type', 'http');
255-
$array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']);
256-
if ($host = data_get($protocol_settings, 'network_settings.header.request.headers.Host')) {
257-
$array['http-opts']['headers']['Host'] = $host;
254+
$headerType = data_get($protocol_settings, 'network_settings.header.type', 'tcp');
255+
$array['network'] = ($headerType === 'http') ? 'http' : 'tcp';
256+
if ($headerType === 'http') {
257+
$array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']);
258+
if ($host = data_get($protocol_settings, 'network_settings.header.request.headers.Host')) {
259+
$array['http-opts']['headers']['Host'] = $host;
260+
}
258261
}
259262
break;
260263
case 'ws':
@@ -312,8 +315,9 @@ public function buildVless($uuid, $server)
312315

313316
switch (data_get($protocol_settings, 'network')) {
314317
case 'tcp':
315-
if ($headerType = data_get($protocol_settings, 'network_settings.header.type', 'tcp') != 'tcp') {
316-
$array['network'] = $headerType;
318+
$headerType = data_get($protocol_settings, 'network_settings.header.type', 'tcp');
319+
$array['network'] = ($headerType === 'http') ? 'http' : 'tcp';
320+
if ($headerType === 'http') {
317321
if ($httpOpts = array_filter([
318322
'headers' => data_get($protocol_settings, 'network_settings.header.request.headers'),
319323
'path' => data_get($protocol_settings, 'network_settings.header.request.path', ['/'])
@@ -355,8 +359,11 @@ public static function buildTrojan($password, $server)
355359
$array['udp'] = true;
356360
switch (data_get($protocol_settings, 'network')) {
357361
case 'tcp':
358-
$array['network'] = data_get($protocol_settings, 'network_settings.header.type');
359-
$array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']);
362+
$headerType = data_get($protocol_settings, 'network_settings.header.type', 'tcp');
363+
$array['network'] = ($headerType === 'http') ? 'http' : 'tcp';
364+
if ($headerType === 'http') {
365+
$array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']);
366+
}
360367
break;
361368
case 'ws':
362369
$array['network'] = 'ws';

0 commit comments

Comments
 (0)