@@ -1,5 +1,9 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
4.3.4 - 2025-09-14
|
||||||
|
---
|
||||||
|
- CHANGE: 改进嵌套加速实现, 增强稳定性
|
||||||
|
|
||||||
4.3.3 - 2025-09-10
|
4.3.3 - 2025-09-10
|
||||||
---
|
---
|
||||||
- CHANGE: 增强对[wanf](https://github.com/WJQSERVER/wanf)的支持
|
- CHANGE: 增强对[wanf](https://github.com/WJQSERVER/wanf)的支持
|
||||||
|
|||||||
@@ -127,18 +127,14 @@ func ChunkedProxyRequest(ctx context.Context, c *touka.Context, u string, cfg *c
|
|||||||
defer bodyReader.Close()
|
defer bodyReader.Close()
|
||||||
|
|
||||||
if MatcherShell(u) && matchString(matcher) && cfg.Shell.Editor {
|
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.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
|
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)
|
c.WriteStream(reader)
|
||||||
if err != nil {
|
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)
|
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
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if contentLength != "" {
|
if contentLength != "" {
|
||||||
c.SetHeader("Content-Length", contentLength)
|
c.SetHeader("Content-Length", contentLength)
|
||||||
c.WriteStream(bodyReader)
|
c.WriteStream(bodyReader)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"compress/gzip"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"ghproxy/config"
|
"ghproxy/config"
|
||||||
"io"
|
"io"
|
||||||
@@ -66,7 +65,7 @@ func modifyURL(url string, host string, cfg *config.Config) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// processLinks 处理链接,返回包含处理后数据的 io.Reader
|
// 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
|
pipeReader, pipeWriter := io.Pipe() // 创建 io.Pipe
|
||||||
readerOut = pipeReader
|
readerOut = pipeReader
|
||||||
|
|
||||||
@@ -97,43 +96,14 @@ func processLinks(input io.ReadCloser, compress string, host string, cfg *config
|
|||||||
|
|
||||||
var bufReader *bufio.Reader
|
var bufReader *bufio.Reader
|
||||||
|
|
||||||
if compress == "gzip" {
|
bufReader = bufio.NewReader(input)
|
||||||
// 解压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)
|
|
||||||
}
|
|
||||||
|
|
||||||
var bufWriter *bufio.Writer
|
var bufWriter *bufio.Writer
|
||||||
var gzipWriter *gzip.Writer
|
|
||||||
|
|
||||||
// 根据是否gzip确定 writer 的创建
|
bufWriter = bufio.NewWriterSize(pipeWriter, 4096) // 使用 pipeWriter
|
||||||
if compress == "gzip" {
|
|
||||||
gzipWriter = gzip.NewWriter(pipeWriter) // 使用 pipeWriter
|
|
||||||
bufWriter = bufio.NewWriterSize(gzipWriter, 4096) //设置缓冲区大小
|
|
||||||
} else {
|
|
||||||
bufWriter = bufio.NewWriterSize(pipeWriter, 4096) // 使用 pipeWriter
|
|
||||||
}
|
|
||||||
|
|
||||||
//确保writer关闭
|
//确保writer关闭
|
||||||
defer func() {
|
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 {
|
if flushErr := bufWriter.Flush(); flushErr != nil {
|
||||||
c.Errorf("writer flush failed %v", flushErr)
|
c.Errorf("writer flush failed %v", flushErr)
|
||||||
// 如果已经存在错误,则保留。否则,记录此错误。
|
// 如果已经存在错误,则保留。否则,记录此错误。
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ var (
|
|||||||
"CDN-Loop": {},
|
"CDN-Loop": {},
|
||||||
"Upgrade": {},
|
"Upgrade": {},
|
||||||
"Connection": {},
|
"Connection": {},
|
||||||
|
"Accept-Encoding": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneHeadersToRemove = map[string]struct{}{
|
cloneHeadersToRemove = map[string]struct{}{
|
||||||
@@ -43,7 +44,7 @@ var (
|
|||||||
var (
|
var (
|
||||||
defaultHeaders = map[string]string{
|
defaultHeaders = map[string]string{
|
||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
"Accept-Encoding": "gzip",
|
"Accept-Encoding": "",
|
||||||
"Transfer-Encoding": "chunked",
|
"Transfer-Encoding": "chunked",
|
||||||
"User-Agent": "GHProxy/1.0",
|
"User-Agent": "GHProxy/1.0",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user