修复循环代理的问题
This commit is contained in:
parent
e2bd4dac50
commit
e060dbe57b
@ -68,13 +68,16 @@ namespace FastGithub
|
|||||||
{
|
{
|
||||||
return listenOptions.UseHttps(https =>
|
return listenOptions.UseHttps(https =>
|
||||||
{
|
{
|
||||||
const string defaultDomain = "github.com";
|
|
||||||
var certs = new ConcurrentDictionary<string, X509Certificate2>();
|
var certs = new ConcurrentDictionary<string, X509Certificate2>();
|
||||||
https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain ?? defaultDomain, CreateCert);
|
https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain, CreateCert);
|
||||||
});
|
});
|
||||||
|
|
||||||
X509Certificate2 CreateCert(string domain)
|
X509Certificate2 CreateCert(string domain)
|
||||||
{
|
{
|
||||||
|
if (domain == string.Empty)
|
||||||
|
{
|
||||||
|
domain = "github.com";
|
||||||
|
}
|
||||||
var domains = new[] { domain };
|
var domains = new[] { domain };
|
||||||
var validFrom = DateTime.Today.AddYears(-1);
|
var validFrom = DateTime.Today.AddYears(-1);
|
||||||
var validTo = DateTime.Today.AddYears(10);
|
var validTo = DateTime.Today.AddYears(10);
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
using FastGithub.ReverseProxy;
|
using FastGithub.ReverseProxy;
|
||||||
|
using FastGithub.Scanner;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Yarp.ReverseProxy.Forwarder;
|
using Yarp.ReverseProxy.Forwarder;
|
||||||
|
|
||||||
namespace FastGithub
|
namespace FastGithub
|
||||||
@ -19,15 +24,22 @@ namespace FastGithub
|
|||||||
{
|
{
|
||||||
var httpForwarder = app.ApplicationServices.GetRequiredService<IHttpForwarder>();
|
var httpForwarder = app.ApplicationServices.GetRequiredService<IHttpForwarder>();
|
||||||
var httpClientFactory = app.ApplicationServices.GetRequiredService<NoneSniHttpClientFactory>();
|
var httpClientFactory = app.ApplicationServices.GetRequiredService<NoneSniHttpClientFactory>();
|
||||||
|
var options = app.ApplicationServices.GetRequiredService<IOptionsMonitor<GithubLookupFactoryOptions>>();
|
||||||
|
|
||||||
app.Use(next => async context =>
|
app.Use(next => async context =>
|
||||||
{
|
{
|
||||||
var hostString = context.Request.Host;
|
var host = context.Request.Host.Host;
|
||||||
var port = hostString.Port ?? 443;
|
if (options.CurrentValue.Domains.Contains(host) == false)
|
||||||
var destinationPrefix = $"http://{hostString.Host}:{port}/";
|
{
|
||||||
|
await context.Response.WriteAsJsonAsync(new { message = $"不支持以{host}访问" });
|
||||||
var httpClient = httpClientFactory.CreateHttpClient();
|
}
|
||||||
await httpForwarder.SendAsync(context, destinationPrefix, httpClient);
|
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;
|
return app;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace FastGithub.Scanner
|
|||||||
/// 域名
|
/// 域名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Options("Lookup")]
|
[Options("Lookup")]
|
||||||
sealed class GithubLookupFactoryOptions
|
public class GithubLookupFactoryOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 反查的域名
|
/// 反查的域名
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user