优化IsMatch性能
This commit is contained in:
parent
002ad37e3b
commit
82e51ab358
@ -28,7 +28,7 @@ namespace FastGithub.Configuration
|
|||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
var opt = options.CurrentValue;
|
var opt = options.CurrentValue;
|
||||||
|
|
||||||
this.domainConfigs = ConvertDomainConfigs(opt.DomainConfigs);
|
this.domainConfigs = ConvertDomainConfigs(opt.DomainConfigs);
|
||||||
this.domainConfigCache = new ConcurrentDictionary<string, DomainConfig?>();
|
this.domainConfigCache = new ConcurrentDictionary<string, DomainConfig?>();
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ namespace FastGithub.Configuration
|
|||||||
private void Update(FastGithubOptions options)
|
private void Update(FastGithubOptions options)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.domainConfigs = ConvertDomainConfigs(options.DomainConfigs);
|
this.domainConfigs = ConvertDomainConfigs(options.DomainConfigs);
|
||||||
this.domainConfigCache = new ConcurrentDictionary<string, DomainConfig?>();
|
this.domainConfigCache = new ConcurrentDictionary<string, DomainConfig?>();
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ namespace FastGithub.Configuration
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool IsMatch(string domain)
|
public bool IsMatch(string domain)
|
||||||
{
|
{
|
||||||
return this.domainConfigs.Keys.Any(item => item.IsMatch(domain));
|
return this.TryGetDomainConfig(domain, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -105,7 +105,7 @@ namespace FastGithub.HttpServer
|
|||||||
return new IPEndPoint(address, targetPort);
|
return new IPEndPoint(address, targetPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.fastGithubConfig.TryGetDomainConfig(targetHost, out _) == false)
|
if (this.fastGithubConfig.IsMatch(targetHost) == false)
|
||||||
{
|
{
|
||||||
return new DnsEndPoint(targetHost, targetPort);
|
return new DnsEndPoint(targetHost, targetPort);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace FastGithub
|
|||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
this.logger.LogInformation($"{nameof(FastGithub)}止停止运行");
|
this.logger.LogInformation($"{nameof(FastGithub)}已停止运行");
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FastGithub
|
namespace FastGithub
|
||||||
{
|
{
|
||||||
@ -59,6 +60,13 @@ namespace FastGithub
|
|||||||
{
|
{
|
||||||
appBuilder.UseRequestLogging();
|
appBuilder.UseRequestLogging();
|
||||||
appBuilder.UseHttpReverseProxy();
|
appBuilder.UseHttpReverseProxy();
|
||||||
|
|
||||||
|
appBuilder.UseRouting();
|
||||||
|
appBuilder.UseEndpoints(endpoint => endpoint.MapFallback(context =>
|
||||||
|
{
|
||||||
|
context.Response.Redirect("https://github.com/dotnetcore/FastGithub");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user