Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Feb 27, 2023
1 parent d5aaa8e commit 46afcae
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 23 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@
- [高级 Web 前端工程师](https://www.zhipin.com/job_detail/e59317c527f3f49e1XJ92d24FVRV.html)
-->

## Windows 目录解构
- modules 模块
- shared 共享运行时
- Microsoft.AspNetCore.App
- Microsoft.NETCore.App
- Steam++.exe 主程序

<!--👇图标如果发生更改,还需更改 Tools.OpenSourceLibraryList(Program.OpenSourceLibraryListEmoji) -->
## 📄 感谢以下开源项目
* [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static class ApplicationBuilderExtensions
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IApplicationBuilder UseHttpProxyPac(this IApplicationBuilder app)
{
var middleware = app.ApplicationServices.GetRequiredService<HttpProxyPacMiddleware>();
Expand All @@ -21,6 +22,7 @@ internal static IApplicationBuilder UseHttpProxyPac(this IApplicationBuilder app
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IApplicationBuilder UseHttpLocalRequest(this IApplicationBuilder app)
{
var middleware = app.ApplicationServices.GetRequiredService<HttpLocalRequestMiddleware>();
Expand All @@ -32,6 +34,7 @@ internal static IApplicationBuilder UseHttpLocalRequest(this IApplicationBuilder
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IApplicationBuilder UseRequestLogging(this IApplicationBuilder app)
{
var middleware = app.ApplicationServices.GetRequiredService<RequestLoggingMiddleware>();
Expand All @@ -43,6 +46,7 @@ internal static IApplicationBuilder UseRequestLogging(this IApplicationBuilder a
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IApplicationBuilder DisableRequestLogging(this IApplicationBuilder app)
{
return app.Use(next => context =>
Expand All @@ -61,6 +65,7 @@ internal static IApplicationBuilder DisableRequestLogging(this IApplicationBuild
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IApplicationBuilder UseHttpReverseProxy(this IApplicationBuilder app)
{
var middleware = app.ApplicationServices.GetRequiredService<HttpReverseProxyMiddleware>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class KestrelServerOptionsExtensions
/// 无限制
/// </summary>
/// <param name="options"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void NoLimit(this KestrelServerOptions options)
{
options.Limits.MaxRequestBodySize = null;
Expand All @@ -20,6 +21,7 @@ public static void NoLimit(this KestrelServerOptions options)
/// 监听 Http 代理
/// </summary>
/// <param name="options"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ListenHttpProxy(this KestrelServerOptions options)
{
var reverseProxyConfig = options.ApplicationServices.GetRequiredService<IReverseProxyConfig>();
Expand All @@ -43,13 +45,16 @@ public static void ListenHttpProxy(this KestrelServerOptions options)
});

options.GetLogger().LogInformation(
$"Listened http://{IReverseProxyService.Instance.ProxyIp}:{httpProxyPort}, HTTP proxy service startup completed.");
"Listened http://{ProxyIp}:{httpProxyPort}, HTTP proxy service startup completed.",
IReverseProxyService.Instance.ProxyIp, httpProxyPort);
}

#if WINDOWS
/// <summary>
/// 监听 SSH 反向代理
/// </summary>
/// <param name="options"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ListenSshReverseProxy(this KestrelServerOptions options)
{
var sshPort = IReverseProxyConfig.SshPort;
Expand All @@ -61,13 +66,16 @@ public static void ListenSshReverseProxy(this KestrelServerOptions options)

var logger = options.GetLogger();
logger.LogInformation(
$"Listened ssh://localhost:{sshPort}, the SSH reverse proxy service of GitHub is started.");
"Listened ssh://localhost:{sshPort}, the SSH reverse proxy service of GitHub is started.", sshPort);
}
#endif

#if WINDOWS
/// <summary>
/// 监听 Git 反向代理
/// </summary>
/// <param name="options"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ListenGitReverseProxy(this KestrelServerOptions options)
{
var gitPort = IReverseProxyConfig.GitPort;
Expand All @@ -79,27 +87,31 @@ public static void ListenGitReverseProxy(this KestrelServerOptions options)

var logger = options.GetLogger();
logger.LogInformation(
$"Listened git://localhost:{gitPort}, the Git reverse proxy service of GitHub has been started.");
"Listened git://localhost:{gitPort}, the Git reverse proxy service of GitHub has been started.", gitPort);
}
#endif

/// <summary>
/// 监听 HTTP 反向代理
/// </summary>
/// <param name="options"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ListenHttpReverseProxy(this KestrelServerOptions options)
{
var httpPort = IReverseProxyConfig.HttpPort;
options.Listen(IReverseProxyService.Instance.ProxyIp, httpPort);

var logger = options.GetLogger();
logger.LogInformation(
$"Listened http://{IReverseProxyService.Instance.ProxyIp}:{httpPort}, HTTP reverse proxy service startup completed.");
"Listened http://{ProxyIp}:{httpPort}, HTTP reverse proxy service startup completed.",
IReverseProxyService.Instance.ProxyIp, httpPort);
}

/// <summary>
/// 监听 HTTPS 反向代理
/// </summary>
/// <param name="options"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ListenHttpsReverseProxy(this KestrelServerOptions options)
{
var certService = options.ApplicationServices.GetRequiredService<CertService>();
Expand All @@ -117,9 +129,11 @@ public static void ListenHttpsReverseProxy(this KestrelServerOptions options)

var logger = options.GetLogger();
logger.LogInformation(
$"Listened https://{IReverseProxyService.Instance.ProxyIp}:{httpsPort}, HTTPS reverse proxy service startup completed.");
"Listened https://{ProxyIp}:{httpsPort}, HTTPS reverse proxy service startup completed.",
IReverseProxyService.Instance.ProxyIp, httpsPort);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ILogger GetLogger(this KestrelServerOptions kestrel)
{
var loggerFactory = kestrel.ApplicationServices.GetRequiredService<ILoggerFactory>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ static partial class ListenOptionsExtensions
/// </summary>
/// <param name="listen"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ListenOptions UseFlowAnalyze(this ListenOptions listen)
{
var flowAnalyzer = listen.ApplicationServices.GetRequiredService<IFlowAnalyzer>();
Expand All @@ -29,10 +30,11 @@ public static ListenOptions UseFlowAnalyze(this ListenOptions listen)
}

/// <summary>
/// 使用Tls中间件
/// 使用 Tls 中间件
/// </summary>
/// <param name="listen"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ListenOptions UseTls(this ListenOptions listen)
{
var certService = listen.ApplicationServices.GetRequiredService<CertService>();
Expand All @@ -42,12 +44,13 @@ public static ListenOptions UseTls(this ListenOptions listen)
}

/// <summary>
/// 使用Tls中间件
/// 使用 Tls 中间件
/// </summary>
/// <param name="listen"></param>
/// <param name="configureOptions">https配置</param>
/// <returns></returns>
private static ListenOptions UseTls(this ListenOptions listen, Action<HttpsConnectionAdapterOptions> configureOptions)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ListenOptions UseTls(this ListenOptions listen, Action<HttpsConnectionAdapterOptions> configureOptions)
{
var invadeMiddleware = listen.ApplicationServices.GetRequiredService<TlsInvadeMiddleware>();
var restoreMiddleware = listen.ApplicationServices.GetRequiredService<TlsRestoreMiddleware>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID)
#if WINDOWS
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.HttpServer/GithubGitReverseProxyHandler.cs

// ReSharper disable once CheckNamespace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID)
#if WINDOWS
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.HttpServer/GithubSshReverseProxyHandler.cs

// ReSharper disable once CheckNamespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ namespace BD.WTTS.Services.Implementation;

partial class YarpReverseProxyServiceImpl
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void StartupConfigureServices(IServiceCollection services)
{
services.Configure<HostOptions>(hostOptions =>
{
// Windows 上有一些情况下无法监听某些端口会抛出异常,忽略后台服务中的异常避免整个 Host 中止
hostOptions.BackgroundServiceExceptionBehavior =
BackgroundServiceExceptionBehavior.Ignore;
});

services.AddConfiguration(this);
services.AddDomainResolve();
services.AddReverseProxyHttpClient();
Expand All @@ -22,7 +30,8 @@ void StartupConfigureServices(IServiceCollection services)
#endif
}

void StartupConfigure(IApplicationBuilder app)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void StartupConfigure(IApplicationBuilder app)
{
app.UseHttpLocalRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,20 @@ bool StartProxyCore()
builder.WebHost.UseKestrel(options =>
{
options.NoLimit();
if (OperatingSystem.IsWindows())
{
#if WINDOWS
#if !NET7_0_OR_GREATER
if (OperatingSystem2.IsWindows7())
if (OperatingSystem2.IsWindows7())
{
//https://github.com/dotnet/aspnetcore/issues/22563
options.ConfigureHttpsDefaults(httpsOptions =>
{
//https://github.com/dotnet/aspnetcore/issues/22563
options.ConfigureHttpsDefaults(httpsOptions =>
{
httpsOptions.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
});
}
#endif
options.ListenSshReverseProxy();
options.ListenGitReverseProxy();
httpsOptions.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
});
}
#endif
options.ListenSshReverseProxy();
options.ListenGitReverseProxy();
#endif

if (ProxyMode is ProxyMode.System or ProxyMode.PAC or ProxyMode.VPN)
{
Expand Down

0 comments on commit 46afcae

Please sign in to comment.