Skip to content

Commit 1db7a04

Browse files
fix(middleware): track actual response size
Fixes incorrect ResponseSize reporting when response body capture is truncated or skipped.
2 parents c4e22fc + 15abbe6 commit 1db7a04

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

DebugProbe.AspNetCore.Tests/Middleware/ResponseBodyCaptureTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public async Task Handles_large_response_within_limit()
4141
await app.Client.GetAsync("/large");
4242

4343
Assert.Equal(body, app.SingleEntry.ResponseBody);
44+
Assert.Equal(body.Length, app.SingleEntry.ResponseSize);
4445
}
4546

4647
[Fact]
@@ -54,6 +55,7 @@ public async Task Handles_binary_response_safely()
5455
await app.Client.GetAsync("/binary");
5556

5657
Assert.Equal("[Body not captured: non-text content]", app.SingleEntry.ResponseBody);
58+
Assert.Equal(4, app.SingleEntry.ResponseSize);
5759
}
5860

5961
[Fact]
@@ -69,5 +71,6 @@ public async Task Validates_bounded_response_capture_behavior()
6971
var entry = app.SingleEntry;
7072
Assert.Equal(body, await response.Content.ReadAsStringAsync());
7173
Assert.Equal("[Body too large]", entry.ResponseBody);
74+
Assert.Equal(body.Length, entry.ResponseSize);
7275
}
7376
}

DebugProbe.AspNetCore/Middleware/DebugProbeMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public async Task Invoke(HttpContext context, DebugEntryStore store)
125125

126126
entry.RequestSize = context.Request.ContentLength ?? Encoding.UTF8.GetByteCount(requestBody);
127127

128-
entry.ResponseSize = Encoding.UTF8.GetByteCount(responseBody);
128+
entry.ResponseSize = responseCapture.TotalBytesWritten;
129129

130130
entry.RequestHeaders =
131131
context.Request.Headers.ToDictionary(

0 commit comments

Comments
 (0)