diff --git a/app/Protocols/Clash.php b/app/Protocols/Clash.php index f0914a2..844f0e2 100644 --- a/app/Protocols/Clash.php +++ b/app/Protocols/Clash.php @@ -203,10 +203,12 @@ class Clash extends AbstractProtocol case 'tcp': $array['network'] = data_get($protocol_settings, 'network_settings.header.type'); if (data_get($protocol_settings, 'network_settings.header.type', 'none') !== 'none') { - $array['http-opts'] = [ + if ($httpOpts = array_filter([ 'headers' => data_get($protocol_settings, 'network_settings.header.request.headers'), 'path' => data_get($protocol_settings, 'network_settings.header.request.path', ['/']) - ]; + ])) { + $array['http-opts'] = $httpOpts; + } } break; case 'ws': diff --git a/app/Protocols/ClashMeta.php b/app/Protocols/ClashMeta.php index 3fc1b10..daa46ce 100644 --- a/app/Protocols/ClashMeta.php +++ b/app/Protocols/ClashMeta.php @@ -261,10 +261,12 @@ class ClashMeta extends AbstractProtocol case 'tcp': $array['network'] = data_get($protocol_settings, 'network_settings.header.type', 'tcp'); if (data_get($protocol_settings, 'network_settings.header.type', 'none') !== 'none') { - $array['http-opts'] = [ + if ($httpOpts = array_filter([ 'headers' => data_get($protocol_settings, 'network_settings.header.request.headers'), 'path' => data_get($protocol_settings, 'network_settings.header.request.path', ['/']) - ]; + ])) { + $array['http-opts'] = $httpOpts; + } } break; case 'ws': diff --git a/app/Protocols/SingBox.php b/app/Protocols/SingBox.php index 5f42500..43a1f3e 100644 --- a/app/Protocols/SingBox.php +++ b/app/Protocols/SingBox.php @@ -209,13 +209,13 @@ class SingBox extends AbstractProtocol 'path' => Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', ['/'])), 'host' => data_get($protocol_settings, 'network_settings.header.request.headers.Host', []) ] : null, - 'ws' => [ + 'ws' => array_filter([ 'type' => 'ws', 'path' => data_get($protocol_settings, 'network_settings.path'), 'headers' => ($host = data_get($protocol_settings, 'network_settings.headers.Host')) ? ['Host' => $host] : null, 'max_early_data' => 2048, 'early_data_header_name' => 'Sec-WebSocket-Protocol' - ], + ]), 'grpc' => [ 'type' => 'grpc', 'service_name' => data_get($protocol_settings, 'network_settings.serviceName') @@ -330,13 +330,13 @@ class SingBox extends AbstractProtocol 'type' => 'grpc', 'service_name' => data_get($protocol_settings, 'network_settings.serviceName') ], - 'ws' => [ + 'ws' => array_filter([ 'type' => 'ws', 'path' => data_get($protocol_settings, 'network_settings.path'), 'headers' => data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => [data_get($protocol_settings, 'network_settings.headers.Host')]] : null, 'max_early_data' => 2048, 'early_data_header_name' => 'Sec-WebSocket-Protocol' - ], + ]), default => null }; $array['transport'] = $transport; diff --git a/app/Protocols/Stash.php b/app/Protocols/Stash.php index 0e5a373..86b63e9 100644 --- a/app/Protocols/Stash.php +++ b/app/Protocols/Stash.php @@ -314,7 +314,12 @@ class Stash extends AbstractProtocol case 'tcp': if ($headerType = data_get($protocol_settings, 'network_settings.header.type', 'tcp') != 'tcp') { $array['network'] = $headerType; - $array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']); + if ($httpOpts = array_filter([ + 'headers' => data_get($protocol_settings, 'network_settings.header.request.headers'), + 'path' => data_get($protocol_settings, 'network_settings.header.request.path', ['/']) + ])) { + $array['http-opts'] = $httpOpts; + } } break; case 'ws': @@ -356,7 +361,9 @@ class Stash extends AbstractProtocol case 'ws': $array['network'] = 'ws'; $array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path'); - $array['ws-opts']['headers'] = data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')] : null; + if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) { + $array['ws-opts']['headers'] = ['Host' => $host]; + } break; } if ($serverName = data_get($protocol_settings, 'server_name')) {