Skip to content

Commit 1d7fe0c

Browse files
Copilotstephentoub
andcommitted
Remove superfluous comment and trim large response bodies
- Remove comment about timeout as suggested by @halter73 - Trim response body to 8KB max for readability, appending "..." if truncated Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 0ab4012 commit 1d7fe0c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/Common/HttpResponseMessageExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace ModelContextProtocol;
88
/// </summary>
99
internal static class HttpResponseMessageExtensions
1010
{
11+
private const int MaxResponseBodyLength = 8 * 1024;
12+
1113
/// <summary>
1214
/// Throws an <see cref="HttpRequestException"/> if the <see cref="HttpResponseMessage.IsSuccessStatusCode"/> property is <see langword="false"/>.
1315
/// Unlike <see cref="HttpResponseMessage.EnsureSuccessStatusCode"/>, this method includes the response body in the exception message
@@ -24,10 +26,14 @@ public static async Task EnsureSuccessStatusCodeWithResponseBodyAsync(this HttpR
2426
string? responseBody = null;
2527
try
2628
{
27-
// Add a timeout to prevent hanging if the server sends an error response but doesn't end the request.
2829
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
2930
cts.CancelAfter(TimeSpan.FromSeconds(5));
3031
responseBody = await response.Content.ReadAsStringAsync(cts.Token).ConfigureAwait(false);
32+
33+
if (responseBody.Length > MaxResponseBodyLength)
34+
{
35+
responseBody = responseBody.Substring(0, MaxResponseBodyLength) + "...";
36+
}
3137
}
3238
catch
3339
{

0 commit comments

Comments
 (0)