修复GitHub release下载失败的问题
This commit is contained in:
parent
e8f0a1181f
commit
26d01669fd
1 changed files with 9 additions and 21 deletions
|
@ -9,7 +9,7 @@ using System.Net; // 用于 URL 解码
|
||||||
namespace iFileProxy.Controllers
|
namespace iFileProxy.Controllers
|
||||||
{
|
{
|
||||||
[Route("/")]
|
[Route("/")]
|
||||||
public class StreamProxyController(IHttpClientFactory httpClientFactory, AppConfig appConfig) : Controller
|
public class StreamProxyController(IHttpClientFactory httpClientFactory, AppConfig appConfig) : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
|
||||||
private long SizeLimit = appConfig.StreamProxyOptions.SizeLimit;
|
private long SizeLimit = appConfig.StreamProxyOptions.SizeLimit;
|
||||||
|
@ -23,34 +23,22 @@ namespace iFileProxy.Controllers
|
||||||
[HttpPatch("{*proxyUrl}")]
|
[HttpPatch("{*proxyUrl}")]
|
||||||
public async Task<IActionResult> ProxyGitRequest(string proxyUrl)
|
public async Task<IActionResult> ProxyGitRequest(string proxyUrl)
|
||||||
{
|
{
|
||||||
DownloadFileInfo downloadFileInfo;
|
DownloadFileInfo? downloadFileInfo;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (proxyUrl.StartsWith("github.com"))
|
||||||
|
proxyUrl = "https://" + proxyUrl;
|
||||||
foreach (var keywords in appConfig.SecurityOptions.BlockedKeyword)
|
foreach (var keywords in appConfig.SecurityOptions.BlockedKeyword)
|
||||||
{
|
{
|
||||||
if (proxyUrl.IndexOf(keywords) != -1)
|
if (proxyUrl.IndexOf(keywords) != -1)
|
||||||
return StatusCode((int)HttpStatusCode.Forbidden, "Keyword::Forbidden");
|
return StatusCode((int)HttpStatusCode.Forbidden, "Keyword::Forbidden");
|
||||||
|
|
||||||
}
|
}
|
||||||
var t = new Uri(proxyUrl);
|
var t = new Uri(proxyUrl);
|
||||||
downloadFileInfo = FileDownloadHelper.GetDownloadFileInfo(proxyUrl);
|
|
||||||
if (downloadFileInfo != null)
|
|
||||||
{
|
|
||||||
if (appConfig.SecurityOptions.BlockedFileName.IndexOf(downloadFileInfo.FileName) != -1)
|
|
||||||
{
|
|
||||||
return StatusCode((int)HttpStatusCode.Forbidden, "This Filename is Blocked");
|
|
||||||
}
|
}
|
||||||
if (appConfig.SecurityOptions.BlockedHost.IndexOf(t.Host) != -1)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return StatusCode((int)HttpStatusCode.Forbidden, "Target Host is Blocked");
|
_logger.Error("[Stream] 解析下载文件时出现问题: {ex}", ex);
|
||||||
}
|
return StatusCode((int)HttpStatusCode.InternalServerError,"服务故障 请联系开发者反馈");
|
||||||
}
|
|
||||||
else
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(proxyUrl))
|
if (string.IsNullOrWhiteSpace(proxyUrl))
|
||||||
|
@ -94,7 +82,7 @@ namespace iFileProxy.Controllers
|
||||||
client.DefaultRequestHeaders.Clear();
|
client.DefaultRequestHeaders.Clear();
|
||||||
|
|
||||||
// 设置目标主机名
|
// 设置目标主机名
|
||||||
client.DefaultRequestHeaders.Host = targetUri.Host;
|
// client.DefaultRequestHeaders.Host = targetUri.Host;
|
||||||
foreach (var header in requestHeaders)
|
foreach (var header in requestHeaders)
|
||||||
{
|
{
|
||||||
// 排除反代理的转发头
|
// 排除反代理的转发头
|
||||||
|
|
Loading…
Reference in a new issue