DisableRequestLogging

This commit is contained in:
陈国伟 2021-11-04 10:48:21 +08:00
parent 1f5309d392
commit 320dfe846c
2 changed files with 21 additions and 8 deletions

View File

@ -17,13 +17,13 @@ namespace FastGithub
/// <returns></returns>
public static IApplicationBuilder UseServerHeader(this IApplicationBuilder app, string serverHeader = nameof(FastGithub))
{
return app.Use(next => async context =>
return app.Use(next => context =>
{
if (context.Response.HasStarted == false)
{
context.Response.Headers.Server = serverHeader;
}
await next(context);
return next(context);
});
}
@ -49,6 +49,24 @@ namespace FastGithub
return app.Use(next => context => middleware.InvokeAsync(context, next));
}
/// <summary>
/// 禁用请求日志中间件
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static IApplicationBuilder DisableRequestLogging(this IApplicationBuilder app)
{
return app.Use(next => context =>
{
var loggingFeature = context.Features.Get<IRequestLoggingFeature>();
if (loggingFeature != null)
{
loggingFeature.Enable = false;
}
return next(context);
});
}
/// <summary>
/// 使用反向代理中间件
/// </summary>

View File

@ -1,6 +1,5 @@
using FastGithub.Configuration;
using FastGithub.FlowAnalyze;
using FastGithub.HttpServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
@ -68,15 +67,11 @@ namespace FastGithub
appBuilder.UseHttpReverseProxy();
appBuilder.UseRouting();
appBuilder.DisableRequestLogging();
appBuilder.UseEndpoints(endpoint =>
{
endpoint.MapGet("/flowStatistics", context =>
{
var loggingFeature = context.Features.Get<IRequestLoggingFeature>();
if (loggingFeature != null)
{
loggingFeature.Enable = false;
}
var flowStatistics = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowStatistics();
return context.Response.WriteAsJsonAsync(flowStatistics);
});