支持shell脚本嵌套代理

This commit is contained in:
NewName
2025-05-18 01:01:42 +00:00
parent 590095eaa4
commit 61cf7ceddd
2 changed files with 206 additions and 2 deletions

View File

@@ -195,8 +195,36 @@ func proxy(c *gin.Context, u string) {
}
c.Status(resp.StatusCode)
if _, err := io.Copy(c.Writer, resp.Body); err != nil {
return
// 检查是否为.sh文件
isShellFile := strings.HasSuffix(strings.ToLower(u), ".sh")
isCompressed := resp.Header.Get("Content-Encoding") == "gzip"
if isShellFile {
// 获取真实域名
realHost := c.Request.Header.Get("X-Forwarded-Host")
if realHost == "" {
realHost = c.Request.Host
}
// 如果域名中没有协议前缀添加https://
if !strings.HasPrefix(realHost, "http://") && !strings.HasPrefix(realHost, "https://") {
realHost = "https://" + realHost
}
// 使用ProcessGitHubURLs处理.sh文件
processedBody, _, err := ProcessGitHubURLs(resp.Body, isCompressed, realHost, true)
if err != nil {
c.String(http.StatusInternalServerError, fmt.Sprintf("处理shell文件时发生错误: %v", err))
return
}
if _, err := io.Copy(c.Writer, processedBody); err != nil {
c.String(http.StatusInternalServerError, fmt.Sprintf("写入响应时发生错误: %v", err))
return
}
} else {
// 对于非.sh文件直接复制响应体
if _, err := io.Copy(c.Writer, resp.Body); err != nil {
return
}
}
}