From 27c777676dbda95533c0080bbf1b110a976d3d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Wed, 10 Nov 2021 08:53:55 +0800 Subject: [PATCH] add server name --- FastGithub.Http/HttpClient.cs | 6 ++++-- .../ApplicationBuilderExtensions.cs | 18 ------------------ FastGithub/Startup.cs | 2 -- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/FastGithub.Http/HttpClient.cs b/FastGithub.Http/HttpClient.cs index 07074bd..7eb5232 100644 --- a/FastGithub.Http/HttpClient.cs +++ b/FastGithub.Http/HttpClient.cs @@ -43,14 +43,16 @@ namespace FastGithub.Http /// /// /// - public override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + public override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (request.Headers.UserAgent.Contains(userAgent)) { throw new FastGithubException($"由于{request.RequestUri}实际指向了{nameof(FastGithub)}自身,{nameof(FastGithub)}已中断本次转发"); } request.Headers.UserAgent.Add(userAgent); - return base.SendAsync(request, cancellationToken); + var response = await base.SendAsync(request, cancellationToken); + response.Headers.Server.TryParseAdd(nameof(FastGithub)); + return response; } } } \ No newline at end of file diff --git a/FastGithub.HttpServer/ApplicationBuilderExtensions.cs b/FastGithub.HttpServer/ApplicationBuilderExtensions.cs index afccc1d..b52daa5 100644 --- a/FastGithub.HttpServer/ApplicationBuilderExtensions.cs +++ b/FastGithub.HttpServer/ApplicationBuilderExtensions.cs @@ -9,24 +9,6 @@ namespace FastGithub /// public static class ApplicationBuilderExtensions { - /// - /// 使用服务头 - /// - /// - /// - /// - public static IApplicationBuilder UseServerHeader(this IApplicationBuilder app, string serverHeader = nameof(FastGithub)) - { - return app.Use(next => context => - { - if (context.Response.HasStarted == false) - { - context.Response.Headers.Server = serverHeader; - } - return next(context); - }); - } - /// /// 使用http代理中间件 /// diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs index 411ef5d..c58df1f 100644 --- a/FastGithub/Startup.cs +++ b/FastGithub/Startup.cs @@ -56,13 +56,11 @@ namespace FastGithub var httpProxyPort = app.ApplicationServices.GetRequiredService>().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();