diff --git a/src/Attributes/EnableLoggingFilterAttribute.cs b/src/Attributes/EnableLoggingFilterAttribute.cs index ccb56d14..d8fd43ee 100644 --- a/src/Attributes/EnableLoggingFilterAttribute.cs +++ b/src/Attributes/EnableLoggingFilterAttribute.cs @@ -13,6 +13,11 @@ public class EnableLoggingFilterAttribute : ApiFilterAttribute { private static readonly LoggingFilterAttribute _loggingFilter = new(); + /// + /// 启用时,不再输出缓存内容。 + /// + public bool EnableCacheLogging { get; set; } = true; + /// /// 请求之前 /// @@ -28,6 +33,16 @@ public async override Task OnRequestAsync(ApiRequestContext context) public async override Task OnResponseAsync(ApiResponseContext context) { if (!IsEnable(context.HttpContext)) return; + + if (EnableCacheLogging + && context.HttpContext.ResponseMessage?.Headers? + .TryGetValues("Response-Cache-Provider", out var values) == true + && values?.Any() == true) + { + context.HttpContext.ResponseMessage ??= new HttpResponseMessage(); + context.HttpContext.ResponseMessage.Content = new StringContent("...来自缓存..."); + } + await _loggingFilter.OnResponseAsync(context); }