This commit is contained in:
wjqserver 2025-04-03 16:39:56 +08:00
parent b02aaeba8a
commit ff412f94ec
14 changed files with 386 additions and 104 deletions

View file

@ -10,7 +10,6 @@ import (
"strconv"
"github.com/cloudwego/hertz/pkg/app"
//hresp "github.com/cloudwego/hertz/pkg/protocol/http1/resp"
)
func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, cfg *config.Config, matcher string) {
@ -31,7 +30,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
return
}
//defer headResp.Body.Close()
defer func(Body io.ReadCloser) {
if err := Body.Close(); err != nil {
logError("Failed to close response body: %v", err)
@ -68,7 +66,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
return
}
//defer resp.Body.Close()
// 错误处理(404)
if resp.StatusCode == 404 {
@ -115,7 +112,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
}
c.Status(resp.StatusCode)
//c.Response.HijackWriter(hresp.NewChunkedBodyWriter(&c.Response, c.GetWriter()))
if MatcherShell(u) && matchString(matcher, matchedMatchers) && cfg.Shell.Editor {
// 判断body是不是gzip
@ -127,7 +123,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
logInfo("Is Shell: %s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol())
c.Header("Content-Length", "")
//err := ProcessLinksAndWriteChunked(resp.Body, compress, string(c.Request.Host()), cfg, c)
reader, _, err := processLinks(resp.Body, compress, string(c.Request.Host()), cfg)
c.SetBodyStream(reader, -1)
@ -136,18 +131,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
return
}
} else {
//err = hwriter.Writer(resp.Body, c)
//writer := c.Response.BodyWriter()
/*
_, err := copyb.Copy(c.Response.BodyWriter(), resp.Body)
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.Header.GetProtocol(), err)
return
} else {
c.Flush() // 确保刷入
}
*/
c.SetBodyStream(resp.Body, -1)
}