Merge branch 'master' of https://github.com/xljiulang/FastGithub
This commit is contained in:
commit
3f4f451435
@ -6,6 +6,7 @@
|
||||
<Copyright>https://github.com/dotnetcore/FastGithub</Copyright>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
||||
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
/// </summary>
|
||||
public class HttpClient : HttpMessageInvoker
|
||||
{
|
||||
/// <summary>
|
||||
/// 插入的UserAgent标记
|
||||
/// </summary>
|
||||
private readonly static ProductInfoHeaderValue userAgent = new(new ProductHeaderValue(nameof(FastGithub), "1.0"));
|
||||
|
||||
/// <summary>
|
||||
/// http客户端
|
||||
/// </summary>
|
||||
@ -28,5 +36,21 @@ namespace FastGithub.Http
|
||||
: base(handler, disposeHandler)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送请求
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override Task<HttpResponseMessage> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,15 +10,15 @@ namespace FastGithub.ReverseProxy
|
||||
/// <summary>
|
||||
/// 请求日志中间件
|
||||
/// </summary>
|
||||
sealed class RequestLoggingMilldeware
|
||||
sealed class RequestLoggingMiddleware
|
||||
{
|
||||
private readonly ILogger<RequestLoggingMilldeware> logger;
|
||||
private readonly ILogger<RequestLoggingMiddleware> logger;
|
||||
|
||||
/// <summary>
|
||||
/// 请求日志中间件
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public RequestLoggingMilldeware(ILogger<RequestLoggingMilldeware> logger)
|
||||
public RequestLoggingMiddleware(ILogger<RequestLoggingMiddleware> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
@ -31,8 +31,7 @@ namespace FastGithub.ReverseProxy
|
||||
/// <returns></returns>
|
||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@ -16,8 +16,8 @@ namespace FastGithub
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseRequestLogging(this IApplicationBuilder app)
|
||||
{
|
||||
var middlware = app.ApplicationServices.GetRequiredService<RequestLoggingMilldeware>();
|
||||
return app.Use(next => context => middlware.InvokeAsync(context, next));
|
||||
var middleware = app.ApplicationServices.GetRequiredService<RequestLoggingMiddleware>();
|
||||
return app.Use(next => context => middleware.InvokeAsync(context, next));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -19,7 +19,7 @@ namespace FastGithub
|
||||
.AddMemoryCache()
|
||||
.AddHttpForwarder()
|
||||
.AddSingleton<CertService>()
|
||||
.AddSingleton<RequestLoggingMilldeware>()
|
||||
.AddSingleton<RequestLoggingMiddleware>()
|
||||
.AddSingleton<ReverseProxyMiddleware>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user