@@ -477,37 +477,21 @@ public async Task ConnectAsync(ConnectionSettings cs, int startTickCount, ILoadB
477
477
{
478
478
Log . Info ( "Session{0} is already redirected; ignoring it." , m_logArguments ) ;
479
479
}
480
- else
480
+ else if ( Utility . TryParseRedirectionHeader ( ok . StatusInfo , out var host , out var port , out var user ) )
481
481
{
482
- var hostIndex = 18 ;
483
- var colonIndex = ok . StatusInfo . IndexOf ( ':' , hostIndex ) ;
484
- if ( colonIndex != - 1 )
485
- {
486
- var host = ok . StatusInfo . Substring ( hostIndex , colonIndex - hostIndex ) ;
487
- var portIndex = colonIndex + 1 ;
488
- var userIndex = ok . StatusInfo . IndexOf ( "/user=" , StringComparison . Ordinal ) ;
489
- if ( userIndex != - 1 )
490
- {
491
- if ( int . TryParse ( ok . StatusInfo . Substring ( portIndex , userIndex - portIndex ) , out var port ) )
492
- {
493
- var ampersandIndex = ok . StatusInfo . IndexOf ( '&' , userIndex ) ;
494
- var userId = ampersandIndex == - 1 ? ok . StatusInfo . Substring ( userIndex + 6 ) : ok . StatusInfo . Substring ( userIndex + 6 , ampersandIndex - userIndex - 6 ) ;
495
- Log . Info ( "Session{0} found server redirection Host={1}; Port={2}; User={3}" , m_logArguments [ 0 ] , host , port , userId ) ;
482
+ Log . Info ( "Session{0} found server redirection Host={1}; Port={2}; User={3}" , m_logArguments [ 0 ] , host , port , user ) ;
496
483
497
- if ( host != cs . HostNames ! [ 0 ] || port != cs . Port || userId != cs . UserID )
498
- {
499
- Log . Info ( "Session{0} closing existing connection" , m_logArguments ) ;
500
- await SendAsync ( QuitPayload . Instance , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
501
- Log . Info ( "Session{0} opening new connection to Host={1}; Port={2}; User={3}" , m_logArguments [ 0 ] , host , port , userId ) ;
502
- cs = cs . CloneWith ( host , port , userId , isRedirected : true ) ;
503
- goto serverRedirection ;
504
- }
505
- else
506
- {
507
- Log . Info ( "Session{0} is already connected to this server; ignoring redirection" , m_logArguments ) ;
508
- }
509
- }
510
- }
484
+ if ( host != cs . HostNames ! [ 0 ] || port != cs . Port || user != cs . UserID )
485
+ {
486
+ Log . Info ( "Session{0} closing existing connection" , m_logArguments ) ;
487
+ await SendAsync ( QuitPayload . Instance , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
488
+ Log . Info ( "Session{0} opening new connection to Host={1}; Port={2}; User={3}" , m_logArguments [ 0 ] , host , port , user ) ;
489
+ cs = cs . CloneWith ( host , port , user , isRedirected : true ) ;
490
+ goto serverRedirection ;
491
+ }
492
+ else
493
+ {
494
+ Log . Info ( "Session{0} is already connected to this server; ignoring redirection" , m_logArguments ) ;
511
495
}
512
496
}
513
497
}
0 commit comments