Improve SSE response handling and URI construction in SseClientSessio… (#251)
This commit is contained in:
parent
43266ad268
commit
cae5dff318
1 changed files with 5 additions and 7 deletions
|
|
@ -115,7 +115,7 @@ internal sealed class SseClientSessionTransport : TransportBase
|
||||||
if (message is JsonRpcRequest request && request.Method == RequestMethods.Initialize)
|
if (message is JsonRpcRequest request && request.Method == RequestMethods.Initialize)
|
||||||
{
|
{
|
||||||
// If the response is not a JSON-RPC response, it is an SSE message
|
// If the response is not a JSON-RPC response, it is an SSE message
|
||||||
if (responseContent.Equals("accepted", StringComparison.OrdinalIgnoreCase))
|
if (string.IsNullOrEmpty(responseContent) || responseContent.Equals("accepted", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
_logger.SSETransportPostAccepted(_endpointName, messageId);
|
_logger.SSETransportPostAccepted(_endpointName, messageId);
|
||||||
// The response will arrive as an SSE message
|
// The response will arrive as an SSE message
|
||||||
|
|
@ -133,7 +133,7 @@ internal sealed class SseClientSessionTransport : TransportBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, check if the response was accepted (the response will come as an SSE message)
|
// Otherwise, check if the response was accepted (the response will come as an SSE message)
|
||||||
if (responseContent.Equals("accepted", StringComparison.OrdinalIgnoreCase))
|
if (string.IsNullOrEmpty(responseContent) || responseContent.Equals("accepted", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
_logger.SSETransportPostAccepted(_endpointName, messageId);
|
_logger.SSETransportPostAccepted(_endpointName, messageId);
|
||||||
}
|
}
|
||||||
|
|
@ -294,13 +294,11 @@ internal sealed class SseClientSessionTransport : TransportBase
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the endpoint is a relative URI, we need to combine it with the relative path of the SSE endpoint
|
// If the endpoint is a relative URI, we need to combine it with the relative path of the SSE endpoint
|
||||||
var hostUrl = _sseEndpoint.AbsoluteUri;
|
var baseUriBuilder = new UriBuilder(_sseEndpoint);
|
||||||
if (hostUrl.EndsWith("/sse", StringComparison.Ordinal))
|
|
||||||
hostUrl = hostUrl[..^4];
|
|
||||||
|
|
||||||
var endpointUri = $"{hostUrl.TrimEnd('/')}/{data.TrimStart('/')}";
|
|
||||||
|
|
||||||
_messageEndpoint = new Uri(endpointUri);
|
// Instead of manually concatenating strings, use the Uri class's composition capabilities
|
||||||
|
_messageEndpoint = new Uri(baseUriBuilder.Uri, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set connected state
|
// Set connected state
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue