@@ -354,11 +354,7 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound)
354354 var host = _node . RequestHost . TrimEx ( ) ;
355355 var path = _node . Path . TrimEx ( ) ;
356356 var sni = _node . Sni . TrimEx ( ) ;
357- var useragent = "" ;
358- if ( ! _config . CoreBasicItem . DefUserAgent . IsNullOrEmpty ( ) )
359- {
360- useragent = Global . UserAgentTexts . GetValueOrDefault ( _config . CoreBasicItem . DefUserAgent , _config . CoreBasicItem . DefUserAgent ) ;
361- }
357+ var useragent = _config . CoreBasicItem . DefUserAgent ?? string . Empty ;
362358
363359 //if tls
364360 if ( _node . StreamSecurity == Global . StreamSecurity )
@@ -496,13 +492,17 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound)
496492 case nameof ( ETransport . httpupgrade ) :
497493 HttpupgradeSettings4Ray httpupgradeSettings = new ( ) ;
498494
495+ if ( host . IsNotEmpty ( ) )
496+ {
497+ httpupgradeSettings . host = host ;
498+ }
499499 if ( path . IsNotEmpty ( ) )
500500 {
501501 httpupgradeSettings . path = path ;
502502 }
503- if ( host . IsNotEmpty ( ) )
503+ if ( useragent . IsNotEmpty ( ) )
504504 {
505- httpupgradeSettings . host = host ;
505+ httpupgradeSettings . headers . UserAgent = useragent ;
506506 }
507507 streamSettings . httpupgradeSettings = httpupgradeSettings ;
508508
@@ -581,6 +581,7 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound)
581581 health_check_timeout = _config . GrpcItem . HealthCheckTimeout ,
582582 permit_without_stream = _config . GrpcItem . PermitWithoutStream ,
583583 initial_windows_size = _config . GrpcItem . InitialWindowsSize ,
584+ user_agent = useragent . NullIfEmpty ( ) ,
584585 } ;
585586 streamSettings . grpcSettings = grpcSettings ;
586587 break ;
@@ -655,10 +656,11 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound)
655656
656657 //request Host
657658 var request = EmbedUtils . GetEmbedText ( Global . V2raySampleHttpRequestFileName ) ;
659+ var useragentValue = Global . TcpHttpUserAgentTexts . GetValueOrDefault ( useragent , useragent ) ;
658660 var arrHost = host . Split ( ',' ) ;
659661 var host2 = string . Join ( "," . AppendQuotes ( ) , arrHost ) ;
660662 request = request . Replace ( "$requestHost$" , $ "{ host2 . AppendQuotes ( ) } ") ;
661- request = request . Replace ( "$requestUserAgent$" , $ "{ useragent . AppendQuotes ( ) } ") ;
663+ request = request . Replace ( "$requestUserAgent$" , $ "{ useragentValue . AppendQuotes ( ) } ") ;
662664 //Path
663665 var pathHttp = @"/" ;
664666 if ( path . IsNotEmpty ( ) )
0 commit comments