修复GitHub release下载失败的问题

This commit is contained in:
root 2024-12-08 23:39:54 +08:00
parent e8f0a1181f
commit 26d01669fd

View file

@ -9,7 +9,7 @@ using System.Net; // 用于 URL 解码
namespace iFileProxy.Controllers
{
[Route("/")]
public class StreamProxyController(IHttpClientFactory httpClientFactory, AppConfig appConfig) : Controller
public class StreamProxyController(IHttpClientFactory httpClientFactory, AppConfig appConfig) : ControllerBase
{
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
private long SizeLimit = appConfig.StreamProxyOptions.SizeLimit;
@ -23,34 +23,22 @@ namespace iFileProxy.Controllers
[HttpPatch("{*proxyUrl}")]
public async Task<IActionResult> ProxyGitRequest(string proxyUrl)
{
DownloadFileInfo downloadFileInfo;
DownloadFileInfo? downloadFileInfo;
try
{
if (proxyUrl.StartsWith("github.com"))
proxyUrl = "https://" + proxyUrl;
foreach (var keywords in appConfig.SecurityOptions.BlockedKeyword)
{
if (proxyUrl.IndexOf(keywords) != -1)
return StatusCode((int)HttpStatusCode.Forbidden, "Keyword::Forbidden");
}
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)
{
return StatusCode((int)HttpStatusCode.Forbidden, "Target Host is Blocked");
}
}
else
return NotFound();
}
catch (Exception)
catch (Exception ex)
{
return NotFound();
_logger.Error("[Stream] 解析下载文件时出现问题: {ex}", ex);
return StatusCode((int)HttpStatusCode.InternalServerError,"服务故障 请联系开发者反馈");
}
if (string.IsNullOrWhiteSpace(proxyUrl))
@ -94,7 +82,7 @@ namespace iFileProxy.Controllers
client.DefaultRequestHeaders.Clear();
// 设置目标主机名
client.DefaultRequestHeaders.Host = targetUri.Host;
// client.DefaultRequestHeaders.Host = targetUri.Host;
foreach (var header in requestHeaders)
{
// 排除反代理的转发头
@ -126,7 +114,7 @@ namespace iFileProxy.Controllers
if (method == HttpMethods.Post || method == HttpMethods.Put || method == HttpMethods.Patch)
{
var content = new StreamContent(Request.Body); // 仅对于 POST/PUT/PATCH 请求,转发请求体
// 处理之前添加失败的请求头
// 处理之前添加失败的请求头
foreach (var header in failedHeaders)
{
content.Headers.Add(header.Key, header.Value);