From 26d01669fdb508806ce56a385c109e126e6987f1 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Dec 2024 23:39:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGitHub=20release=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controllers/StreamProxyController.cs | 30 +++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/Controllers/StreamProxyController.cs b/src/Controllers/StreamProxyController.cs index 37ce313..44e5483 100644 --- a/src/Controllers/StreamProxyController.cs +++ b/src/Controllers/StreamProxyController.cs @@ -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 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);