diff --git a/FastGithub.ReverseProxy/ApplicationBuilderExtensions.cs b/FastGithub.HttpServer/ApplicationBuilderExtensions.cs similarity index 97% rename from FastGithub.ReverseProxy/ApplicationBuilderExtensions.cs rename to FastGithub.HttpServer/ApplicationBuilderExtensions.cs index ae00c6b..1262795 100644 --- a/FastGithub.ReverseProxy/ApplicationBuilderExtensions.cs +++ b/FastGithub.HttpServer/ApplicationBuilderExtensions.cs @@ -1,4 +1,4 @@ -using FastGithub.ReverseProxy; +using FastGithub.HttpServer; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; diff --git a/FastGithub.ReverseProxy/CertGenerator.cs b/FastGithub.HttpServer/CertGenerator.cs similarity index 99% rename from FastGithub.ReverseProxy/CertGenerator.cs rename to FastGithub.HttpServer/CertGenerator.cs index 8c6c539..4ddd01b 100644 --- a/FastGithub.ReverseProxy/CertGenerator.cs +++ b/FastGithub.HttpServer/CertGenerator.cs @@ -19,7 +19,7 @@ using System.Net; using System.Text; using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// 证书生成器 diff --git a/FastGithub.ReverseProxy/CertService.cs b/FastGithub.HttpServer/CertService.cs similarity index 95% rename from FastGithub.ReverseProxy/CertService.cs rename to FastGithub.HttpServer/CertService.cs index 67821f9..679d7b0 100644 --- a/FastGithub.ReverseProxy/CertService.cs +++ b/FastGithub.HttpServer/CertService.cs @@ -9,14 +9,14 @@ using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// 证书服务 /// sealed class CertService { - private const string CACert_PATH = "cacert"; + private const string CACERT_PATH = "cacert"; private const int KEY_SIZE_BITS = 2048; private readonly IMemoryCache serverCertCache; private readonly ILogger logger; @@ -25,12 +25,12 @@ namespace FastGithub.ReverseProxy /// /// 获取证书文件路径 /// - public string CaCerFilePath { get; } = $"{CACert_PATH}/fastgithub.cer"; + public string CaCerFilePath { get; } = $"{CACERT_PATH}/fastgithub.cer"; /// /// 获取私钥文件路径 /// - public string CaKeyFilePath { get; } = $"{CACert_PATH}/fastgithub.key"; + public string CaKeyFilePath { get; } = $"{CACERT_PATH}/fastgithub.key"; /// /// 证书服务 @@ -42,8 +42,7 @@ namespace FastGithub.ReverseProxy { this.serverCertCache = serverCertCache; this.logger = logger; - - Directory.CreateDirectory(CACert_PATH); + Directory.CreateDirectory(CACERT_PATH); } /// diff --git a/FastGithub.ReverseProxy/FastGithub.ReverseProxy.csproj b/FastGithub.HttpServer/FastGithub.HttpServer.csproj similarity index 100% rename from FastGithub.ReverseProxy/FastGithub.ReverseProxy.csproj rename to FastGithub.HttpServer/FastGithub.HttpServer.csproj diff --git a/FastGithub.ReverseProxy/HttpProxyMiddleware.cs b/FastGithub.HttpServer/HttpProxyMiddleware.cs similarity index 96% rename from FastGithub.ReverseProxy/HttpProxyMiddleware.cs rename to FastGithub.HttpServer/HttpProxyMiddleware.cs index 6a87873..0b5980c 100644 --- a/FastGithub.ReverseProxy/HttpProxyMiddleware.cs +++ b/FastGithub.HttpServer/HttpProxyMiddleware.cs @@ -11,7 +11,7 @@ using System.Text; using System.Threading.Tasks; using Yarp.ReverseProxy.Forwarder; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// http代理中间件 @@ -96,8 +96,9 @@ namespace FastGithub.ReverseProxy /// private async Task GetTargetEndPointAsync(HttpRequest request) { + const int HTTPS_PORT = 443; var targetHost = request.Host.Host; - var targetPort = request.Host.Port ?? 443; + var targetPort = request.Host.Port ?? HTTPS_PORT; if (IPAddress.TryParse(targetHost, out var address) == true) { @@ -110,7 +111,7 @@ namespace FastGithub.ReverseProxy } // https,走反向代理中间人 - if (targetPort == 443) + if (targetPort == HTTPS_PORT) { return new IPEndPoint(IPAddress.Loopback, HttpsReverseProxyPort.Value); } diff --git a/FastGithub.ReverseProxy/HttpReverseProxyMiddleware.cs b/FastGithub.HttpServer/HttpReverseProxyMiddleware.cs similarity index 99% rename from FastGithub.ReverseProxy/HttpReverseProxyMiddleware.cs rename to FastGithub.HttpServer/HttpReverseProxyMiddleware.cs index 5041045..45c2a06 100644 --- a/FastGithub.ReverseProxy/HttpReverseProxyMiddleware.cs +++ b/FastGithub.HttpServer/HttpReverseProxyMiddleware.cs @@ -6,7 +6,7 @@ using System; using System.Threading.Tasks; using Yarp.ReverseProxy.Forwarder; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// 反向代理中间件 diff --git a/FastGithub.ReverseProxy/HttpsReverseProxyPort.cs b/FastGithub.HttpServer/HttpsReverseProxyPort.cs similarity index 92% rename from FastGithub.ReverseProxy/HttpsReverseProxyPort.cs rename to FastGithub.HttpServer/HttpsReverseProxyPort.cs index 0fa5181..4427715 100644 --- a/FastGithub.ReverseProxy/HttpsReverseProxyPort.cs +++ b/FastGithub.HttpServer/HttpsReverseProxyPort.cs @@ -2,7 +2,7 @@ using System; using System.Net.Sockets; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// https反向代理端口 diff --git a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs b/FastGithub.HttpServer/KestrelServerOptionsExtensions.cs similarity index 89% rename from FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs rename to FastGithub.HttpServer/KestrelServerOptionsExtensions.cs index 78daefb..c3dfaac 100644 --- a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs +++ b/FastGithub.HttpServer/KestrelServerOptionsExtensions.cs @@ -1,5 +1,5 @@ using FastGithub.Configuration; -using FastGithub.ReverseProxy; +using FastGithub.HttpServer; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; @@ -41,7 +41,7 @@ namespace FastGithub var logger = kestrel.GetLogger(); kestrel.Listen(IPAddress.Loopback, httpProxyPort); - logger.LogInformation($"已监听http://127.0.0.1:{httpProxyPort},http代理服务启动完成"); + logger.LogInformation($"已监听http://{IPAddress.Loopback}:{httpProxyPort},http代理服务启动完成"); } /// @@ -54,7 +54,7 @@ namespace FastGithub if (LocalMachine.CanListenTcp(SSH_PORT) == true) { kestrel.Listen(IPAddress.Loopback, SSH_PORT, listen => listen.UseConnectionHandler()); - kestrel.GetLogger().LogInformation($"已监听ssh://127.0.0.1:{SSH_PORT},github的ssh反向代理服务启动完成"); + kestrel.GetLogger().LogInformation($"已监听ssh://{IPAddress.Loopback}:{SSH_PORT},github的ssh反向代理服务启动完成"); } } @@ -68,7 +68,7 @@ namespace FastGithub if (LocalMachine.CanListenTcp(HTTP_PORT) == true) { kestrel.Listen(IPAddress.Loopback, HTTP_PORT); - kestrel.GetLogger().LogInformation($"已监听http://127.0.0.1:{HTTP_PORT},http反向代理服务启动完成"); + kestrel.GetLogger().LogInformation($"已监听http://{IPAddress.Loopback}:{HTTP_PORT},http反向代理服务启动完成"); } } @@ -103,7 +103,7 @@ namespace FastGithub if (httpsPort == 443) { var logger = kestrel.GetLogger(); - logger.LogInformation($"已监听https://127.0.0.1:{httpsPort},https反向代理服务启动完成"); + logger.LogInformation($"已监听https://{IPAddress.Loopback}:{httpsPort},https反向代理服务启动完成"); } return httpsPort; @@ -117,7 +117,7 @@ namespace FastGithub private static ILogger GetLogger(this KestrelServerOptions kestrel) { var loggerFactory = kestrel.ApplicationServices.GetRequiredService(); - return loggerFactory.CreateLogger($"{nameof(FastGithub)}.{nameof(ReverseProxy)}"); + return loggerFactory.CreateLogger($"{nameof(FastGithub)}.{nameof(HttpServer)}"); } } } diff --git a/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs b/FastGithub.HttpServer/RequestLoggingMilldeware.cs similarity index 98% rename from FastGithub.ReverseProxy/RequestLoggingMilldeware.cs rename to FastGithub.HttpServer/RequestLoggingMilldeware.cs index d08da59..1771311 100644 --- a/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs +++ b/FastGithub.HttpServer/RequestLoggingMilldeware.cs @@ -8,7 +8,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// 请求日志中间件 diff --git a/FastGithub.ReverseProxy/ServiceCollectionExtensions.cs b/FastGithub.HttpServer/ServiceCollectionExtensions.cs similarity index 96% rename from FastGithub.ReverseProxy/ServiceCollectionExtensions.cs rename to FastGithub.HttpServer/ServiceCollectionExtensions.cs index 92a65cb..4151824 100644 --- a/FastGithub.ReverseProxy/ServiceCollectionExtensions.cs +++ b/FastGithub.HttpServer/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -using FastGithub.ReverseProxy; +using FastGithub.HttpServer; using Microsoft.Extensions.DependencyInjection; namespace FastGithub diff --git a/FastGithub.ReverseProxy/SshReverseProxyHandler.cs b/FastGithub.HttpServer/SshReverseProxyHandler.cs similarity index 97% rename from FastGithub.ReverseProxy/SshReverseProxyHandler.cs rename to FastGithub.HttpServer/SshReverseProxyHandler.cs index d08d764..0cdf324 100644 --- a/FastGithub.ReverseProxy/SshReverseProxyHandler.cs +++ b/FastGithub.HttpServer/SshReverseProxyHandler.cs @@ -5,7 +5,7 @@ using System.Net; using System.Net.Sockets; using System.Threading.Tasks; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// github的ssh代理处理者 diff --git a/FastGithub.ReverseProxy/TcpTable.cs b/FastGithub.HttpServer/TcpTable.cs similarity index 99% rename from FastGithub.ReverseProxy/TcpTable.cs rename to FastGithub.HttpServer/TcpTable.cs index 0ac1cca..9737305 100644 --- a/FastGithub.ReverseProxy/TcpTable.cs +++ b/FastGithub.HttpServer/TcpTable.cs @@ -6,7 +6,7 @@ using System.Net.Sockets; using System.Runtime.InteropServices; using System.Runtime.Versioning; -namespace FastGithub.ReverseProxy +namespace FastGithub.HttpServer { /// /// windows iphlpapi diff --git a/FastGithub.sln b/FastGithub.sln index 628e704..40a868f 100644 --- a/FastGithub.sln +++ b/FastGithub.sln @@ -7,14 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub", "FastGithub\Fa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Dns", "FastGithub.Dns\FastGithub.Dns.csproj", "{43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.ReverseProxy", "FastGithub.ReverseProxy\FastGithub.ReverseProxy.csproj", "{28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Http", "FastGithub.Http\FastGithub.Http.csproj", "{B5DCB3E4-5094-4170-B844-6F395002CA42}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.DomainResolve", "FastGithub.DomainResolve\FastGithub.DomainResolve.csproj", "{5D26ABDD-F341-4EB7-9D08-FCB80F79B4B4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Configuration", "FastGithub.Configuration\FastGithub.Configuration.csproj", "{C63CEBB1-56DA-4AC3-BDC9-52424EC292A0}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.HttpServer", "FastGithub.HttpServer\FastGithub.HttpServer.csproj", "{C9807DA0-4620-445E-ABBF-57A617B8E773}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,10 +29,6 @@ Global {43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}.Debug|Any CPU.Build.0 = Debug|Any CPU {43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}.Release|Any CPU.ActiveCfg = Release|Any CPU {43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}.Release|Any CPU.Build.0 = Release|Any CPU - {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Release|Any CPU.Build.0 = Release|Any CPU {B5DCB3E4-5094-4170-B844-6F395002CA42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B5DCB3E4-5094-4170-B844-6F395002CA42}.Debug|Any CPU.Build.0 = Debug|Any CPU {B5DCB3E4-5094-4170-B844-6F395002CA42}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -45,6 +41,10 @@ Global {C63CEBB1-56DA-4AC3-BDC9-52424EC292A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {C63CEBB1-56DA-4AC3-BDC9-52424EC292A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {C63CEBB1-56DA-4AC3-BDC9-52424EC292A0}.Release|Any CPU.Build.0 = Release|Any CPU + {C9807DA0-4620-445E-ABBF-57A617B8E773}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9807DA0-4620-445E-ABBF-57A617B8E773}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9807DA0-4620-445E-ABBF-57A617B8E773}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9807DA0-4620-445E-ABBF-57A617B8E773}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FastGithub/FastGithub.csproj b/FastGithub/FastGithub.csproj index a866968..b3a7101 100644 --- a/FastGithub/FastGithub.csproj +++ b/FastGithub/FastGithub.csproj @@ -14,7 +14,7 @@ - +