修复unix平台不能访问带-的域名的bug (#68)

This commit is contained in:
陈国伟 2021-10-11 13:30:10 +08:00
parent 44960eb4fc
commit f0de9adfc6

View File

@ -3,10 +3,12 @@ using FastGithub.DomainResolve;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using System.IO.Pipelines;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Yarp.ReverseProxy.Forwarder;
@ -28,6 +30,20 @@ namespace FastGithub.HttpServer
private readonly HttpMessageInvoker defaultHttpClient;
static HttpProxyMiddleware()
{
// https://github.com/dotnet/aspnetcore/issues/37421
var authority = typeof(HttpParser<>).Assembly
.GetType("Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.HttpCharacters")?
.GetField("_authority", BindingFlags.NonPublic | BindingFlags.Static)?
.GetValue(null);
if (authority is bool[] authorityArray)
{
authorityArray['-'] = true;
}
}
/// <summary>
/// http代理中间件
/// </summary>