From ec6871a6140eae4fda12dcec9fa3533dd59da665 Mon Sep 17 00:00:00 2001 From: weihanli Date: Thu, 12 Aug 2021 22:43:04 +0800 Subject: [PATCH 1/3] DisableImplicitNamespaceImport for latest .NET 6 Preview would break on build --- Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Build.props b/Directory.Build.props index 794a16d..16339cb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,6 +6,7 @@ https://github.com/dotnetcore/FastGithub win-x64 net5.0;net6.0 + true From e21bb9999488ade9a7e3af196b559b85c43d926f Mon Sep 17 00:00:00 2001 From: weihanli Date: Thu, 12 Aug 2021 22:48:55 +0800 Subject: [PATCH 2/3] Fix some warnings and typo --- FastGithub.ReverseProxy/RequestLoggingMilldeware.cs | 9 ++++----- .../ReverseProxyApplicationBuilderExtensions.cs | 4 ++-- .../ReverseProxyServiceCollectionExtensions.cs | 2 +- FastGithub/Views/_ViewStart.cshtml | 4 +--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs b/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs index e838031..38423d2 100644 --- a/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs +++ b/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs @@ -10,15 +10,15 @@ namespace FastGithub.ReverseProxy /// /// 请求日志中间件 /// - sealed class RequestLoggingMilldeware + sealed class RequestLoggingMiddleware { - private readonly ILogger logger; + private readonly ILogger logger; /// /// 请求日志中间件 /// /// - public RequestLoggingMilldeware(ILogger logger) + public RequestLoggingMiddleware(ILogger logger) { this.logger = logger; } @@ -31,8 +31,7 @@ namespace FastGithub.ReverseProxy /// public async Task InvokeAsync(HttpContext context, RequestDelegate next) { - var stopwatch = new Stopwatch(); - stopwatch.Start(); + var stopwatch = Stopwatch.StartNew(); try { diff --git a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs index be7febd..8fcad59 100644 --- a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs +++ b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs @@ -16,8 +16,8 @@ namespace FastGithub /// public static IApplicationBuilder UseRequestLogging(this IApplicationBuilder app) { - var middlware = app.ApplicationServices.GetRequiredService(); - return app.Use(next => context => middlware.InvokeAsync(context, next)); + var middleware = app.ApplicationServices.GetRequiredService(); + return app.Use(next => context => middleware.InvokeAsync(context, next)); } /// diff --git a/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs index 1e1bddd..ea7bb81 100644 --- a/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs +++ b/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs @@ -19,7 +19,7 @@ namespace FastGithub .AddMemoryCache() .AddHttpForwarder() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton(); } } diff --git a/FastGithub/Views/_ViewStart.cshtml b/FastGithub/Views/_ViewStart.cshtml index a5f1004..5f28270 100644 --- a/FastGithub/Views/_ViewStart.cshtml +++ b/FastGithub/Views/_ViewStart.cshtml @@ -1,3 +1 @@ -@{ - Layout = "_Layout"; -} + \ No newline at end of file From 1b40882dc351e576407e60928ce13b03f63e7767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Fri, 13 Aug 2021 09:12:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=BD=AC=E5=8F=91=E6=AD=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E6=A3=80=E6=B5=8B(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.DomainResolve/DomainResolver.cs | 6 ------ FastGithub.Http/HttpClient.cs | 24 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/FastGithub.DomainResolve/DomainResolver.cs b/FastGithub.DomainResolve/DomainResolver.cs index 2dd894f..ee1d2a5 100644 --- a/FastGithub.DomainResolve/DomainResolver.cs +++ b/FastGithub.DomainResolve/DomainResolver.cs @@ -97,12 +97,6 @@ namespace FastGithub.DomainResolve throw new FastGithubException($"dns{dns}解析不到{domain}的ip"); } - // 不允许域名解析指向FastGithub自身造成消息死循环 - if (LocalMachine.ContainsIPAddress(address) == true) - { - throw new FastGithubException($"dns{dns}被污染,解析{domain}为{address}"); - } - this.logger.LogInformation($"[{domain}->{address}]"); return address; } diff --git a/FastGithub.Http/HttpClient.cs b/FastGithub.Http/HttpClient.cs index 2ff0389..910fb19 100644 --- a/FastGithub.Http/HttpClient.cs +++ b/FastGithub.Http/HttpClient.cs @@ -1,6 +1,9 @@ using FastGithub.Configuration; using FastGithub.DomainResolve; using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; namespace FastGithub.Http { @@ -9,6 +12,11 @@ namespace FastGithub.Http /// public class HttpClient : HttpMessageInvoker { + /// + /// 插入的UserAgent标记 + /// + private readonly static ProductInfoHeaderValue userAgent = new(new ProductHeaderValue(nameof(FastGithub), "1.0")); + /// /// http客户端 /// @@ -28,5 +36,21 @@ namespace FastGithub.Http : base(handler, disposeHandler) { } + + /// + /// 发送请求 + /// + /// + /// + /// + public override 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); + } } } \ No newline at end of file