@@ -65,24 +65,25 @@ private async Task InitializeAsync(JsonRpcMessage message, CancellationToken can
6565 {
6666 LogAttemptingStreamableHttp ( _name ) ;
6767 using var response = await streamableHttpTransport . SendHttpRequestAsync ( message , cancellationToken ) . ConfigureAwait ( false ) ;
68-
69- // If the status code is not success, fall back to SSE
70- if ( ! response . IsSuccessStatusCode )
68+
69+ if ( response . IsSuccessStatusCode )
70+ {
71+ LogUsingStreamableHttp ( _name ) ;
72+ ActiveTransport = streamableHttpTransport ;
73+ }
74+ else
7175 {
76+ // If the status code is not success, fall back to SSE
7277 LogStreamableHttpFailed ( _name , response . StatusCode ) ;
73-
78+
7479 await streamableHttpTransport . DisposeAsync ( ) . ConfigureAwait ( false ) ;
7580 await InitializeSseTransportAsync ( message , cancellationToken ) . ConfigureAwait ( false ) ;
76- return ;
7781 }
78-
79- LogUsingStreamableHttp ( _name ) ;
80- ActiveTransport = streamableHttpTransport ;
8182 }
8283 catch
8384 {
8485 // If nothing threw inside the try block, we've either set streamableHttpTransport as the
85- // ActiveTransport, or else we will have disposed it in the !IsSuccessStatusCode if statement .
86+ // ActiveTransport, or else we will have disposed it in the !IsSuccessStatusCode else block .
8687 await streamableHttpTransport . DisposeAsync ( ) . ConfigureAwait ( false ) ;
8788 throw ;
8889 }
@@ -97,7 +98,7 @@ private async Task InitializeSseTransportAsync(JsonRpcMessage message, Cancellat
9798 LogAttemptingSSE ( _name ) ;
9899 await sseTransport . ConnectAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
99100 await sseTransport . SendMessageAsync ( message , cancellationToken ) . ConfigureAwait ( false ) ;
100-
101+
101102 LogUsingSSE ( _name ) ;
102103 ActiveTransport = sseTransport ;
103104 }
@@ -124,7 +125,7 @@ public async ValueTask DisposeAsync()
124125 _messageChannel . Writer . TryComplete ( ) ;
125126 }
126127 }
127-
128+
128129 [ LoggerMessage ( Level = LogLevel . Debug , Message = "{EndpointName} attempting to connect using Streamable HTTP transport." ) ]
129130 private partial void LogAttemptingStreamableHttp ( string endpointName ) ;
130131
@@ -133,10 +134,10 @@ public async ValueTask DisposeAsync()
133134
134135 [ LoggerMessage ( Level = LogLevel . Information , Message = "{EndpointName} using Streamable HTTP transport." ) ]
135136 private partial void LogUsingStreamableHttp ( string endpointName ) ;
136-
137+
137138 [ LoggerMessage ( Level = LogLevel . Debug , Message = "{EndpointName} attempting to connect using SSE transport." ) ]
138139 private partial void LogAttemptingSSE ( string endpointName ) ;
139-
140+
140141 [ LoggerMessage ( Level = LogLevel . Information , Message = "{EndpointName} using SSE transport." ) ]
141142 private partial void LogUsingSSE ( string endpointName ) ;
142143}
0 commit comments