UseServerHeader

This commit is contained in:
陈国伟 2021-11-03 13:44:01 +08:00
parent 3d26368839
commit 388db6f061
2 changed files with 18 additions and 1 deletions

View File

@ -9,6 +9,21 @@ namespace FastGithub
/// </summary>
public static class ApplicationBuilderExtensions
{
/// <summary>
/// 使用服务头
/// </summary>
/// <param name="app"></param>
/// <param name="serverHeader"></param>
/// <returns></returns>
public static IApplicationBuilder UseServerHeader(this IApplicationBuilder app, string serverHeader = nameof(FastGithub))
{
return app.Use(next => async context =>
{
await next(context);
context.Response.Headers.Server = serverHeader;
});
}
/// <summary>
/// 使用http代理中间件
/// </summary>

View File

@ -57,14 +57,16 @@ namespace FastGithub
var httpProxyPort = app.ApplicationServices.GetRequiredService<IOptions<FastGithubOptions>>().Value.HttpProxyPort;
app.MapWhen(context => context.Connection.LocalPort == httpProxyPort, appBuilder =>
{
appBuilder.UseServerHeader();
appBuilder.UseHttpProxy();
});
app.MapWhen(context => context.Connection.LocalPort != httpProxyPort, appBuilder =>
{
appBuilder.UseServerHeader();
appBuilder.UseRequestLogging();
appBuilder.UseHttpReverseProxy();
appBuilder.UseRouting();
appBuilder.UseEndpoints(endpoint =>
{