From bd9f590b0ac6a3d94a320f0bf7db76526d0761ea Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 14 Sep 2025 07:31:41 +0800 Subject: [PATCH] 4.3.4 --- CHANGELOG.md | 4 ++++ proxy/chunkreq.go | 11 +++-------- proxy/nest.go | 36 +++--------------------------------- proxy/reqheader.go | 3 ++- 4 files changed, 12 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e7720..5987eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +4.3.4 - 2025-09-10 +--- +- CHANGE: 改进嵌套加速实现, 增强稳定性 + 4.3.3 - 2025-09-10 --- - CHANGE: 增强对[wanf](https://github.com/WJQSERVER/wanf)的支持 diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 9227b78..7e3725e 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -127,18 +127,14 @@ func ChunkedProxyRequest(ctx context.Context, c *touka.Context, u string, cfg *c defer bodyReader.Close() if MatcherShell(u) && matchString(matcher) && cfg.Shell.Editor { - // 判断body是不是gzip - var compress string - if resp.Header.Get("Content-Encoding") == "gzip" { - compress = "gzip" - } c.Debugf("Use Shell Editor: %s %s %s %s %s", c.ClientIP(), c.Request.Method, u, c.UserAgent(), c.Request.Proto) - c.Header("Content-Length", "") + c.DelHeader("Content-Length") + c.DelHeader("Content-Encoding") var reader io.Reader - reader, _, err = processLinks(bodyReader, compress, c.Request.Host, cfg, c) + reader, _, err = processLinks(bodyReader, c.Request.Host, cfg, c) c.WriteStream(reader) if err != nil { c.Errorf("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), c.Request.Method, u, c.UserAgent(), c.Request.Proto, err) @@ -146,7 +142,6 @@ func ChunkedProxyRequest(ctx context.Context, c *touka.Context, u string, cfg *c return } } else { - if contentLength != "" { c.SetHeader("Content-Length", contentLength) c.WriteStream(bodyReader) diff --git a/proxy/nest.go b/proxy/nest.go index 4f93f20..675e4a3 100644 --- a/proxy/nest.go +++ b/proxy/nest.go @@ -2,7 +2,6 @@ package proxy import ( "bufio" - "compress/gzip" "fmt" "ghproxy/config" "io" @@ -66,7 +65,7 @@ func modifyURL(url string, host string, cfg *config.Config) string { } // processLinks 处理链接,返回包含处理后数据的 io.Reader -func processLinks(input io.ReadCloser, compress string, host string, cfg *config.Config, c *touka.Context) (readerOut io.Reader, written int64, err error) { +func processLinks(input io.ReadCloser, host string, cfg *config.Config, c *touka.Context) (readerOut io.Reader, written int64, err error) { pipeReader, pipeWriter := io.Pipe() // 创建 io.Pipe readerOut = pipeReader @@ -97,43 +96,14 @@ func processLinks(input io.ReadCloser, compress string, host string, cfg *config var bufReader *bufio.Reader - if compress == "gzip" { - // 解压gzip - gzipReader, gzipErr := gzip.NewReader(input) - if gzipErr != nil { - err = fmt.Errorf("gzip解压错误: %v", gzipErr) - return // Goroutine 中使用 return 返回错误 - } - defer gzipReader.Close() - bufReader = bufio.NewReader(gzipReader) - } else { - bufReader = bufio.NewReader(input) - } + bufReader = bufio.NewReader(input) var bufWriter *bufio.Writer - var gzipWriter *gzip.Writer - // 根据是否gzip确定 writer 的创建 - if compress == "gzip" { - gzipWriter = gzip.NewWriter(pipeWriter) // 使用 pipeWriter - bufWriter = bufio.NewWriterSize(gzipWriter, 4096) //设置缓冲区大小 - } else { - bufWriter = bufio.NewWriterSize(pipeWriter, 4096) // 使用 pipeWriter - } + bufWriter = bufio.NewWriterSize(pipeWriter, 4096) // 使用 pipeWriter //确保writer关闭 defer func() { - var closeErr error // 局部变量,用于保存defer中可能发生的错误 - - if gzipWriter != nil { - if closeErr = gzipWriter.Close(); closeErr != nil { - c.Errorf("gzipWriter close failed %v", closeErr) - // 如果已经存在错误,则保留。否则,记录此错误。 - if err == nil { - err = closeErr - } - } - } if flushErr := bufWriter.Flush(); flushErr != nil { c.Errorf("writer flush failed %v", flushErr) // 如果已经存在错误,则保留。否则,记录此错误。 diff --git a/proxy/reqheader.go b/proxy/reqheader.go index c89dc76..57d8542 100644 --- a/proxy/reqheader.go +++ b/proxy/reqheader.go @@ -27,6 +27,7 @@ var ( "CDN-Loop": {}, "Upgrade": {}, "Connection": {}, + "Accept-Encoding": {}, } cloneHeadersToRemove = map[string]struct{}{ @@ -43,7 +44,7 @@ var ( var ( defaultHeaders = map[string]string{ "Accept": "*/*", - "Accept-Encoding": "gzip", + "Accept-Encoding": "", "Transfer-Encoding": "chunked", "User-Agent": "GHProxy/1.0", }