fix: ignore empty Streamable HTTP JSON responses (#1626)
This commit is contained in:
parent
1f9b8a3955
commit
ffc557f920
1 changed files with 39 additions and 2 deletions
|
|
@ -147,6 +147,40 @@ public class HttpClientTransportTests : LoggedTest
|
|||
Assert.True(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StreamableHttp_NotificationWithEmptyAcceptedJsonResponse_DoesNotLogParseFailure()
|
||||
{
|
||||
var options = new HttpClientTransportOptions
|
||||
{
|
||||
Endpoint = new Uri("http://localhost:8080/mcp"),
|
||||
TransportMode = HttpTransportMode.StreamableHttp,
|
||||
};
|
||||
|
||||
using var mockHttpHandler = new MockHttpHandler();
|
||||
using var httpClient = new HttpClient(mockHttpHandler);
|
||||
await using var transport = new HttpClientTransport(options, httpClient, LoggerFactory);
|
||||
|
||||
mockHttpHandler.RequestHandler = request =>
|
||||
{
|
||||
Assert.Equal(HttpMethod.Post, request.Method);
|
||||
Assert.Equal("http://localhost:8080/mcp", request.RequestUri?.AbsoluteUri);
|
||||
|
||||
return Task.FromResult(new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.Accepted,
|
||||
Content = new StringContent("", Encoding.UTF8, "application/json"),
|
||||
});
|
||||
};
|
||||
|
||||
await using var session = await transport.ConnectAsync(TestContext.Current.CancellationToken);
|
||||
await session.SendMessageAsync(
|
||||
new JsonRpcNotification { Method = "notifications/initialized" },
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
Assert.DoesNotContain(MockLoggerProvider.LogMessages, log =>
|
||||
log.Message.Contains("transport message parsing failed", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendMessageAsync_Throws_HttpRequestException_With_ResponseBody_On_ErrorStatusCode()
|
||||
{
|
||||
|
|
@ -377,4 +411,4 @@ public class HttpClientTransportTests : LoggedTest
|
|||
// Assert - Total GET requests = 1 initial connection + MaxReconnectionAttempts reconnections.
|
||||
Assert.Equal(1 + MaxReconnectionAttempts, getRequestCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue