Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions DebugProbe.AspNetCore/Middleware/DebugProbeMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,34 @@ public async Task Invoke(HttpContext context, DebugEntryStore store)

var started = Stopwatch.StartNew();

var exception = false;

try
{
await _next(context);
}
catch
{
exception = true;
throw;
}
finally
{
started.Stop();

ms.Position = 0;
var responseBody = await new StreamReader(ms).ReadToEndAsync();
ms.Position = 0;
await ms.CopyToAsync(originalBody);

await ms.CopyToAsync(originalBody);
context.Response.Body = originalBody;

var shortDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
var index = shortDatePattern.LastIndexOf('y');
var dataFormat = index >= 0 ? shortDatePattern[..(index + 1)] : shortDatePattern;

var statusCode = exception && context.Response.StatusCode == 200 ? 500 : context.Response.StatusCode;

store.Add(new DebugEntry
{
Id = Guid.NewGuid().ToString(),
Expand All @@ -80,7 +89,7 @@ public async Task Invoke(HttpContext context, DebugEntryStore store)
Method = context.Request.Method,
Path = context.Request.Path,
Query = context.Request.QueryString.ToString(),
StatusCode = context.Response.StatusCode,
StatusCode = statusCode,
RequestTimeUtc = DateTime.UtcNow,
DurationMs = started.ElapsedMilliseconds,
RequestSize = Encoding.UTF8.GetByteCount(requestBody),
Expand Down