diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Azure.Sdk.Tools.TestProxy.csproj b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Azure.Sdk.Tools.TestProxy.csproj index 1fa934582d3..274d5a4c52e 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Azure.Sdk.Tools.TestProxy.csproj +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Azure.Sdk.Tools.TestProxy.csproj @@ -9,7 +9,6 @@ preview $(OfficialBuildId) false - test-proxy diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs index 3ff9760b04e..b064a7e3ca9 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http.Extensions; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Configuration; +using System.Net.Http; namespace Azure.Sdk.Tools.TestProxy.Common { @@ -159,6 +160,21 @@ public static async Task LogRequestDetailsAsync(ILogger loggerInstance, HttpRequ } } + /// + /// Helper function used to evaluate an incoming httprequest and non-destructively log some information about it using a provided logger instance. When not + /// actually logging anything, this function is entirely passthrough. + /// + /// Usually will be the DI-ed individual ILogger instance from a controller. However any valid ILogger instance is fine here. + /// The http request which needs to be detailed. + /// + public static async Task LogResponseDetailsAsync(ILogger loggerInstance, HttpResponseMessage resp) + { + if (CheckLogLevel(LogLevel.Debug)) + { + loggerInstance.LogDebug(await _generateLogLine(resp)); + } + } + /// /// Helper function used to evaluate an incoming httprequest and non-destructively log some information about it using the non-DI logger instance. When not /// actually logging anything, this function is entirely passthrough. @@ -173,6 +189,44 @@ public static async Task LogRequestDetailsAsync(HttpRequest req) } } + + /// + /// Helper function used to evaluate an incoming httprequest and non-destructively log some information about it using the non-DI logger instance. When not + /// actually logging anything, this function is entirely passthrough. + /// + /// The http request which needs to be detailed. + /// + public static async Task LogResponseDetailsAsync(HttpResponseMessage resp) + { + if (CheckLogLevel(LogLevel.Debug)) + { + logger.LogDebug(await _generateLogLine(resp)); + } + } + + /// + /// Generate a line of data from an http request. This is non-destructive, which means it does not mess + /// with the request Body stream at all. + /// + /// + /// + private static async Task _generateLogLine(HttpResponseMessage resp) + { + StringBuilder sb = new StringBuilder(); + string headers = string.Empty; + + using (MemoryStream ms = new MemoryStream()) + { + await JsonSerializer.SerializeAsync(ms, resp.Headers); + headers = Encoding.UTF8.GetString(ms.ToArray()); + } + + sb.AppendLine("URI: [ " + resp.StatusCode + "]"); + sb.AppendLine("Headers: [" + headers + "]"); + + return sb.ToString(); + } + /// /// Generate a line of data from an http request. This is non-destructive, which means it does not mess /// with the request Body stream at all. @@ -191,6 +245,7 @@ private static async Task _generateLogLine(HttpRequest req) } sb.AppendLine("URI: [ " + req.GetDisplayUrl() + "]"); + sb.AppendLine("Verb: [" + req.Method + "]"); sb.AppendLine("Headers: [" + headers + "]"); return sb.ToString(); diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index 0206a7ad844..be0bd078c73 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -227,6 +227,7 @@ public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incom upstreamResponse = await (session.Client ?? RedirectlessClient).SendAsync(upstreamRequest).ConfigureAwait(false); } + await DebugLogger.LogResponseDetailsAsync(upstreamResponse); byte[] body = Array.Empty(); // HEAD requests do NOT have a body regardless of the value of the Content-Length header diff --git a/tools/test-proxy/ci.yml b/tools/test-proxy/ci.yml index dd45c7298bd..e9c1e20f523 100644 --- a/tools/test-proxy/ci.yml +++ b/tools/test-proxy/ci.yml @@ -50,14 +50,14 @@ extends: stableTags: - 'latest' ReleaseBinaries: true - StandaloneExeMatrix: - - rid: osx-x64 - framework: net6.0 - - rid: osx-arm64 - framework: net6.0 - - rid: win-x64 - framework: net6.0 - - rid: linux-x64 - framework: net6.0 - - rid: linux-arm64 - framework: net6.0 + # StandaloneExeMatrix: + # - rid: osx-x64 + # framework: net6.0 + # - rid: osx-arm64 + # framework: net6.0 + # - rid: win-x64 + # framework: net6.0 + # - rid: linux-x64 + # framework: net6.0 + # - rid: linux-arm64 + # framework: net6.0