diff --git a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs index 0a9534b..b15a742 100644 --- a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs +++ b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs @@ -68,13 +68,16 @@ namespace FastGithub { return listenOptions.UseHttps(https => { - const string defaultDomain = "github.com"; var certs = new ConcurrentDictionary(); - https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain ?? defaultDomain, CreateCert); + https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain, CreateCert); }); X509Certificate2 CreateCert(string domain) { + if (domain == string.Empty) + { + domain = "github.com"; + } var domains = new[] { domain }; var validFrom = DateTime.Today.AddYears(-1); var validTo = DateTime.Today.AddYears(10); diff --git a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs index 885c50b..5bc71cd 100644 --- a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs +++ b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs @@ -1,6 +1,11 @@ using FastGithub.ReverseProxy; +using FastGithub.Scanner; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System; +using System.Linq; using Yarp.ReverseProxy.Forwarder; namespace FastGithub @@ -19,15 +24,22 @@ namespace FastGithub { var httpForwarder = app.ApplicationServices.GetRequiredService(); var httpClientFactory = app.ApplicationServices.GetRequiredService(); + var options = app.ApplicationServices.GetRequiredService>(); app.Use(next => async context => { - var hostString = context.Request.Host; - var port = hostString.Port ?? 443; - var destinationPrefix = $"http://{hostString.Host}:{port}/"; - - var httpClient = httpClientFactory.CreateHttpClient(); - await httpForwarder.SendAsync(context, destinationPrefix, httpClient); + var host = context.Request.Host.Host; + if (options.CurrentValue.Domains.Contains(host) == false) + { + await context.Response.WriteAsJsonAsync(new { message = $"不支持以{host}访问" }); + } + else + { + var port = context.Request.Host.Port ?? 443; + var destinationPrefix = $"http://{host}:{port}/"; + var httpClient = httpClientFactory.CreateHttpClient(); + await httpForwarder.SendAsync(context, destinationPrefix, httpClient); + } }); return app; diff --git a/FastGithub.Scanner/GithubLookupFactoryOptions.cs b/FastGithub.Scanner/GithubLookupFactoryOptions.cs index 3b70056..298c4f7 100644 --- a/FastGithub.Scanner/GithubLookupFactoryOptions.cs +++ b/FastGithub.Scanner/GithubLookupFactoryOptions.cs @@ -6,7 +6,7 @@ namespace FastGithub.Scanner /// 域名 /// [Options("Lookup")] - sealed class GithubLookupFactoryOptions + public class GithubLookupFactoryOptions { /// /// 反查的域名