@@ -115,7 +115,7 @@ public override async Task SendMessageAsync(
115
115
if ( message is JsonRpcRequest request && request . Method == RequestMethods . Initialize )
116
116
{
117
117
// If the response is not a JSON-RPC response, it is an SSE message
118
- if ( responseContent . Equals ( "accepted" , StringComparison . OrdinalIgnoreCase ) )
118
+ if ( string . IsNullOrEmpty ( responseContent ) || responseContent . Equals ( "accepted" , StringComparison . OrdinalIgnoreCase ) )
119
119
{
120
120
_logger . SSETransportPostAccepted ( _endpointName , messageId ) ;
121
121
// The response will arrive as an SSE message
@@ -133,7 +133,7 @@ public override async Task SendMessageAsync(
133
133
}
134
134
135
135
// Otherwise, check if the response was accepted (the response will come as an SSE message)
136
- if ( responseContent . Equals ( "accepted" , StringComparison . OrdinalIgnoreCase ) )
136
+ if ( string . IsNullOrEmpty ( responseContent ) || responseContent . Equals ( "accepted" , StringComparison . OrdinalIgnoreCase ) )
137
137
{
138
138
_logger . SSETransportPostAccepted ( _endpointName , messageId ) ;
139
139
}
@@ -294,13 +294,11 @@ private void HandleEndpointEvent(string data)
294
294
else
295
295
{
296
296
// If the endpoint is a relative URI, we need to combine it with the relative path of the SSE endpoint
297
- var hostUrl = _sseEndpoint . AbsoluteUri ;
298
- if ( hostUrl . EndsWith ( "/sse" , StringComparison . Ordinal ) )
299
- hostUrl = hostUrl [ ..^ 4 ] ;
297
+ var baseUriBuilder = new UriBuilder ( _sseEndpoint ) ;
300
298
301
- var endpointUri = $ "{ hostUrl . TrimEnd ( '/' ) } /{ data . TrimStart ( '/' ) } ";
302
299
303
- _messageEndpoint = new Uri ( endpointUri ) ;
300
+ // Instead of manually concatenating strings, use the Uri class's composition capabilities
301
+ _messageEndpoint = new Uri ( baseUriBuilder . Uri , data ) ;
304
302
}
305
303
306
304
// Set connected state
0 commit comments