diff --git a/GetIntoTeachingApi/Middleware/RequestResponseLoggingMiddleware.cs b/GetIntoTeachingApi/Middleware/RequestResponseLoggingMiddleware.cs index b98d8aada..6b557636a 100644 --- a/GetIntoTeachingApi/Middleware/RequestResponseLoggingMiddleware.cs +++ b/GetIntoTeachingApi/Middleware/RequestResponseLoggingMiddleware.cs @@ -1,6 +1,6 @@ using System.IO; using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using GetIntoTeachingApi.Utils; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; @@ -28,7 +28,6 @@ public RequestResponseLoggingMiddleware( public async Task Invoke(HttpContext context) { - await LogRequest(context); await LogResponse(context); } @@ -83,18 +82,6 @@ private bool ShouldLogPayload(string method, string path) return _config.CompactLoggingPatterns.All(regex => !regex.IsMatch(input)); } - private async Task LogRequest(HttpContext context) - { - context.Request.EnableBuffering(); - - // Copy request body stream, resetting position for next middleware. - await using var stream = _recyclableMemoryStreamManager.GetStream(); - await context.Request.Body.CopyToAsync(stream); - context.Request.Body.Position = 0; - - LogInformation("HTTP Request", ReadStream(stream), context.Request); - } - private async Task LogResponse(HttpContext context) { // Keep track of the original response body stream (its read-once). diff --git a/GetIntoTeachingApiTests/Middleware/RequestResponseLoggingMiddlewareTests.cs b/GetIntoTeachingApiTests/Middleware/RequestResponseLoggingMiddlewareTests.cs index bd3af992c..8e4037e5f 100644 --- a/GetIntoTeachingApiTests/Middleware/RequestResponseLoggingMiddlewareTests.cs +++ b/GetIntoTeachingApiTests/Middleware/RequestResponseLoggingMiddlewareTests.cs @@ -55,8 +55,7 @@ public async Task Invoke_WithJsonPayloadAndCompactLoggingPath_LogsRequestAndResp _context.Request.QueryString, Payload = string.Empty, }; - - _mockLogger.VerifyInformationWasCalled($"HTTP Request: {expectedInfo}"); + _mockLogger.VerifyInformationWasCalled($"HTTP Response: {expectedInfo}"); } @@ -88,8 +87,7 @@ public async Task Invoke_WithJsonPayload_LogsRequestAndResponseWithRedactedPaylo _context.Request.QueryString, Payload = redactedJson, }; - - _mockLogger.VerifyInformationWasCalled($"HTTP Request: {expectedInfo}"); + _mockLogger.VerifyInformationWasCalled($"HTTP Response: {expectedInfo}"); } @@ -108,8 +106,7 @@ public async Task Invoke_WithNonJsonPayload_LogsRequestAndResponseWithEmptyPaylo _context.Request.QueryString, Payload = string.Empty, }; - - _mockLogger.VerifyInformationWasCalled($"HTTP Request: {expectedInfo}"); + _mockLogger.VerifyInformationWasCalled($"HTTP Response: {expectedInfo}"); }