mirror of
https://gitee.com/dotnetchina/Furion.git
synced 2025-12-06 15:59:25 +08:00
😊 修复 HTTP 远程请求分析工具存在重复打印问题
This commit is contained in:
@@ -96,6 +96,12 @@ internal static class Constants
|
||||
/// <remarks>被用于从 <see cref="HttpRequestMessage" /> 的 <c>Options</c> 属性中读取。</remarks>
|
||||
internal const string DISABLE_PROFILER_KEY = "__DISABLE_PROFILER__";
|
||||
|
||||
/// <summary>
|
||||
/// 请求分析工具打印标识键
|
||||
/// </summary>
|
||||
/// <remarks>解决重复打印问题。被用于从 <see cref="HttpRequestMessage" /> 的 <c>Options</c> 属性中读取。</remarks>
|
||||
internal const string PROFILER_PRINTED_KEY = "__PROFILER_PRINTED__";
|
||||
|
||||
/// <summary>
|
||||
/// 启用 JSON 响应反序列化包装器键
|
||||
/// </summary>
|
||||
|
||||
@@ -55,9 +55,18 @@ public sealed class ProfilerDelegatingHandler(IHttpRemoteLogger logger, IOptions
|
||||
/// <returns>
|
||||
/// <see cref="bool" />
|
||||
/// </returns>
|
||||
internal static bool IsEnabled(HttpRequestMessage httpRequestMessage) =>
|
||||
!(httpRequestMessage.Options.TryGetValue(new HttpRequestOptionsKey<string>(Constants.DISABLE_PROFILER_KEY),
|
||||
out var value) && value == "TRUE");
|
||||
internal static bool IsEnabled(HttpRequestMessage httpRequestMessage)
|
||||
{
|
||||
// 检查是否已打印过
|
||||
if (httpRequestMessage.Options.TryGetValue(new HttpRequestOptionsKey<string>(Constants.PROFILER_PRINTED_KEY),
|
||||
out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(httpRequestMessage.Options.TryGetValue(
|
||||
new HttpRequestOptionsKey<string>(Constants.DISABLE_PROFILER_KEY), out var value) && value == "TRUE");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override HttpResponseMessage Send(HttpRequestMessage httpRequestMessage,
|
||||
|
||||
@@ -456,6 +456,9 @@ internal sealed partial class HttpRemoteService : IHttpRemoteService
|
||||
// 检查是否启用请求分析工具
|
||||
if (httpRequestBuilder.ProfilerEnabled)
|
||||
{
|
||||
// 标记已打印,解决重复打印问题
|
||||
httpRequestMessage.Options.TryAdd(Constants.PROFILER_PRINTED_KEY, "TRUE");
|
||||
|
||||
// 初始化 HttpRemoteAnalyzer 实例
|
||||
httpRemoteAnalyzer = httpRequestBuilder.ProfilerPredicate is not null ? new HttpRemoteAnalyzer() : null;
|
||||
|
||||
|
||||
@@ -96,6 +96,12 @@ internal static class Constants
|
||||
/// <remarks>被用于从 <see cref="HttpRequestMessage" /> 的 <c>Options</c> 属性中读取。</remarks>
|
||||
internal const string DISABLE_PROFILER_KEY = "__DISABLE_PROFILER__";
|
||||
|
||||
/// <summary>
|
||||
/// 请求分析工具打印标识键
|
||||
/// </summary>
|
||||
/// <remarks>解决重复打印问题。被用于从 <see cref="HttpRequestMessage" /> 的 <c>Options</c> 属性中读取。</remarks>
|
||||
internal const string PROFILER_PRINTED_KEY = "__PROFILER_PRINTED__";
|
||||
|
||||
/// <summary>
|
||||
/// 启用 JSON 响应反序列化包装器键
|
||||
/// </summary>
|
||||
|
||||
@@ -55,9 +55,18 @@ public sealed class ProfilerDelegatingHandler(IHttpRemoteLogger logger, IOptions
|
||||
/// <returns>
|
||||
/// <see cref="bool" />
|
||||
/// </returns>
|
||||
internal static bool IsEnabled(HttpRequestMessage httpRequestMessage) =>
|
||||
!(httpRequestMessage.Options.TryGetValue(new HttpRequestOptionsKey<string>(Constants.DISABLE_PROFILER_KEY),
|
||||
out var value) && value == "TRUE");
|
||||
internal static bool IsEnabled(HttpRequestMessage httpRequestMessage)
|
||||
{
|
||||
// 检查是否已打印过
|
||||
if (httpRequestMessage.Options.TryGetValue(new HttpRequestOptionsKey<string>(Constants.PROFILER_PRINTED_KEY),
|
||||
out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(httpRequestMessage.Options.TryGetValue(
|
||||
new HttpRequestOptionsKey<string>(Constants.DISABLE_PROFILER_KEY), out var value) && value == "TRUE");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override HttpResponseMessage Send(HttpRequestMessage httpRequestMessage,
|
||||
|
||||
@@ -456,6 +456,9 @@ internal sealed partial class HttpRemoteService : IHttpRemoteService
|
||||
// 检查是否启用请求分析工具
|
||||
if (httpRequestBuilder.ProfilerEnabled)
|
||||
{
|
||||
// 标记已打印,解决重复打印问题
|
||||
httpRequestMessage.Options.TryAdd(Constants.PROFILER_PRINTED_KEY, "TRUE");
|
||||
|
||||
// 初始化 HttpRemoteAnalyzer 实例
|
||||
httpRemoteAnalyzer = httpRequestBuilder.ProfilerPredicate is not null ? new HttpRemoteAnalyzer() : null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user