forked from ycjyy/FastGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
621 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ttpServer/CaCertInstallerOfLinuxDebian.cs → ...nstallers/CaCertInstallerOfLinuxDebian.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ttpServer/CaCertInstallerOfLinuxRedHat.cs → ...nstallers/CaCertInstallerOfLinuxRedHat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
FastGithub.HttpServer/ICaCertInstaller.cs → ...thub.HttpServer/Certs/ICaCertInstaller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace FastGithub.HttpServer | ||
namespace FastGithub.HttpServer.Certs | ||
{ | ||
/// <summary> | ||
/// CA证书安装器 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
FastGithub.HttpServer/HttpMiddlewares/HttpProxyPacMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using FastGithub.Configuration; | ||
using FastGithub.HttpServer.TcpMiddlewares; | ||
using Microsoft.AspNetCore.Http; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FastGithub.HttpServer.HttpMiddlewares | ||
{ | ||
/// <summary> | ||
/// http代理策略中间件 | ||
/// </summary> | ||
sealed class HttpProxyPacMiddleware | ||
{ | ||
private readonly FastGithubConfig fastGithubConfig; | ||
|
||
/// <summary> | ||
/// http代理策略中间件 | ||
/// </summary> | ||
/// <param name="fastGithubConfig"></param> | ||
public HttpProxyPacMiddleware(FastGithubConfig fastGithubConfig) | ||
{ | ||
this.fastGithubConfig = fastGithubConfig; | ||
} | ||
|
||
/// <summary> | ||
/// 处理请求 | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <param name="next"></param> | ||
/// <returns></returns> | ||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
{ | ||
// http请求经过了httpProxy中间件 | ||
var proxyFeature = context.Features.Get<IHttpProxyFeature>(); | ||
if (proxyFeature != null && proxyFeature.ProxyProtocol == ProxyProtocol.None) | ||
{ | ||
var proxyPac = this.CreateProxyPac(context.Request.Host); | ||
context.Response.ContentType = "application/x-ns-proxy-autoconfig"; | ||
context.Response.Headers.Add("Content-Disposition", $"attachment;filename=proxy.pac"); | ||
await context.Response.WriteAsync(proxyPac); | ||
} | ||
else | ||
{ | ||
await next(context); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 创建proxypac脚本 | ||
/// </summary> | ||
/// <param name="proxyHost"></param> | ||
/// <returns></returns> | ||
private string CreateProxyPac(HostString proxyHost) | ||
{ | ||
var buidler = new StringBuilder(); | ||
buidler.AppendLine("function FindProxyForURL(url, host){"); | ||
buidler.AppendLine($" var fastgithub = 'PROXY {proxyHost}';"); | ||
foreach (var domain in fastGithubConfig.GetDomainPatterns()) | ||
{ | ||
buidler.AppendLine($" if (shExpMatch(host, '{domain}')) return fastgithub;"); | ||
} | ||
buidler.AppendLine(" return 'DIRECT';"); | ||
buidler.AppendLine("}"); | ||
return buidler.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...thub.HttpServer/IRequestLoggingFeature.cs → ...HttpMiddlewares/IRequestLoggingFeature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace FastGithub.HttpServer | ||
namespace FastGithub.HttpServer.HttpMiddlewares | ||
{ | ||
/// <summary> | ||
/// 请求日志特性 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.