This commit is contained in:
wjqserver 2025-03-18 21:53:59 +08:00
parent ac7e1e43b5
commit a92bbb7fb6
22 changed files with 685 additions and 316 deletions

View file

@ -2,6 +2,7 @@ package proxy
import (
"bytes"
"context"
"fmt"
"ghproxy/config"
"io"
@ -10,13 +11,12 @@ import (
"strconv"
"strings"
"github.com/WJQSERVER-STUDIO/go-utils/copyb"
"github.com/gin-gonic/gin"
"github.com/WJQSERVER-STUDIO/go-utils/hwriter"
"github.com/cloudwego/hertz/pkg/app"
)
func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
method := c.Request.Method
logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Config, mode string, runMode string) {
method := string(c.Request.Method())
logDump("Url Before FMT:%s", u)
if cfg.GitClone.Mode == "cache" {
@ -35,11 +35,7 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s
err error
)
body, err := readRequestBody(c)
if err != nil {
HandleError(c, err.Error())
return
}
body := c.Request.Body()
bodyReader := bytes.NewBuffer(body)
// 创建请求
@ -85,9 +81,9 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s
size, err := strconv.Atoi(contentLength)
sizelimit := cfg.Server.SizeLimit * 1024 * 1024
if err == nil && size > sizelimit {
finalURL := resp.Request.URL.String()
finalURL := []byte(resp.Request.URL.String())
c.Redirect(http.StatusMovedPermanently, finalURL)
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Path(), c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol(), finalURL, size)
return
}
}
@ -127,21 +123,22 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s
_, err = io.CopyBuffer(c.Writer, resp.Body, buffer)
if err != nil {
logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol(), err)
return
} else {
c.Writer.Flush() // 确保刷入
}
*/
_, err = copyb.CopyBuffer(c.Writer, resp.Body, nil)
//_, err = copyb.CopyBuffer(c, resp.Body, nil)
err = hwriter.Writer(resp.Body, c)
if err != nil {
logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol(), err)
return
} else {
c.Writer.Flush() // 确保刷入
c.Flush() // 确保刷入
}
}