From f633086bd70a9cd30d2a4189bd5672ead35097e1 Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Tue, 31 Jan 2023 13:44:46 -0800 Subject: [PATCH] additional logging --- .../Common/DebugLogger.cs | 4 +-- .../RecordingHandler.cs | 30 ++++++++++++------- .../appsettings.json | 3 +- 3 files changed, 23 insertions(+), 14 deletions(-) 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 b064a7e3ca9..a220c488236 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs @@ -221,8 +221,8 @@ private static async Task _generateLogLine(HttpResponseMessage resp) headers = Encoding.UTF8.GetString(ms.ToArray()); } - sb.AppendLine("URI: [ " + resp.StatusCode + "]"); - sb.AppendLine("Headers: [" + headers + "]"); + sb.AppendLine("Response Statuscode: [ " + resp.StatusCode + "]"); + sb.AppendLine("Response 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 be0bd078c73..d4bd582198d 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -187,7 +187,7 @@ public async Task StartRecordingAsync(string sessionId, HttpResponse outgoingRes public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incomingRequest, HttpResponse outgoingResponse) { - await DebugLogger.LogRequestDetailsAsync(incomingRequest); + //await DebugLogger.LogRequestDetailsAsync(incomingRequest); if (!RecordingSessions.TryGetValue(recordingId, out var session)) { @@ -477,11 +477,14 @@ public static async Task CreateEntryAsync(HttpRequest request) entry.RequestUri = GetRequestUri(request).AbsoluteUri; entry.RequestMethod = new RequestMethod(request.Method); - foreach (var header in request.Headers) + lock (request.Headers) { - if (IncludeHeader(header.Key)) + foreach (var header in request.Headers) { - entry.Request.Headers.Add(header.Key, header.Value.ToArray()); + if (IncludeHeader(header.Key)) + { + entry.Request.Headers.Add(header.Key, header.Value.ToArray()); + } } } @@ -956,14 +959,19 @@ public static string GetHeader(HttpRequest request, string name, bool allowNulls public static Uri GetRequestUri(HttpRequest request) { - // Instead of obtaining the Path of the request from request.Path, we use this - // more complicated method obtaining the raw string from the httpcontext. Unfortunately, - // The native request functions implicitly decode the Path value. EG: "aa%27bb" is decoded into 'aa'bb'. - // Using the RawTarget PREVENTS this automatic decode. We still lean on the URI constructors - // to give us some amount of safety, but note that we explicitly disable escaping in that combination. - var rawTarget = request.HttpContext.Features.Get().RawTarget; - var hostValue = GetHeader(request, "x-recording-upstream-base-uri"); + string rawTarget = string.Empty; + string hostValue = string.Empty; + lock (request) + { + // Instead of obtaining the Path of the request from request.Path, we use this + // more complicated method obtaining the raw string from the httpcontext. Unfortunately, + // The native request functions implicitly decode the Path value. EG: "aa%27bb" is decoded into 'aa'bb'. + // Using the RawTarget PREVENTS this automatic decode. We still lean on the URI constructors + // to give us some amount of safety, but note that we explicitly disable escaping in that combination. + rawTarget = request.HttpContext.Features.Get().RawTarget; + hostValue = GetHeader(request, "x-recording-upstream-base-uri"); + } // it is easy to forget the x-recording-upstream-base-uri value if (string.IsNullOrWhiteSpace(hostValue)) { diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/appsettings.json b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/appsettings.json index d9d9a9bff6f..fda3d745ba9 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/appsettings.json +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/appsettings.json @@ -6,5 +6,6 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + }