Skip to content

Commit

Permalink
include rename of tool back to azure.sdk.tools.testproxy. eliminate t…
Browse files Browse the repository at this point in the history
…he executable matrix so this thing will complete and allow me to have the .net folks try this
  • Loading branch information
scbedd committed Jan 31, 2023
1 parent 01fc067 commit fb73696
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<LangVersion>preview</LangVersion>
<InformationalVersion>$(OfficialBuildId)</InformationalVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<AssemblyName>test-proxy</AssemblyName>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net5.0'">
Expand Down
55 changes: 55 additions & 0 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -159,6 +160,21 @@ public static async Task LogRequestDetailsAsync(ILogger loggerInstance, HttpRequ
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="loggerInstance">Usually will be the DI-ed individual ILogger instance from a controller. However any valid ILogger instance is fine here.</param>
/// <param name="resp">The http request which needs to be detailed.</param>
/// <returns></returns>
public static async Task LogResponseDetailsAsync(ILogger loggerInstance, HttpResponseMessage resp)
{
if (CheckLogLevel(LogLevel.Debug))
{
loggerInstance.LogDebug(await _generateLogLine(resp));
}
}

/// <summary>
/// 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.
Expand All @@ -173,6 +189,44 @@ public static async Task LogRequestDetailsAsync(HttpRequest req)
}
}


/// <summary>
/// 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.
/// </summary>
/// <param name="resp">The http request which needs to be detailed.</param>
/// <returns></returns>
public static async Task LogResponseDetailsAsync(HttpResponseMessage resp)
{
if (CheckLogLevel(LogLevel.Debug))
{
logger.LogDebug(await _generateLogLine(resp));
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="resp"></param>
/// <returns></returns>
private static async Task<string> _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();
}

/// <summary>
/// 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.
Expand All @@ -191,6 +245,7 @@ private static async Task<string> _generateLogLine(HttpRequest req)
}

sb.AppendLine("URI: [ " + req.GetDisplayUrl() + "]");
sb.AppendLine("Verb: [" + req.Method + "]");
sb.AppendLine("Headers: [" + headers + "]");

return sb.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>();

// HEAD requests do NOT have a body regardless of the value of the Content-Length header
Expand Down
22 changes: 11 additions & 11 deletions tools/test-proxy/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fb73696

Please sign in to comment.