支持shell脚本嵌套代理
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user