mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 16:21:11 +08:00
25w04c
This commit is contained in:
parent
ef332a24e5
commit
e0af54370e
5 changed files with 30 additions and 5 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -1,5 +1,15 @@
|
|||
# 更新日志
|
||||
|
||||
25w04c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2的候选版本,请勿在生产环境中使用;
|
||||
- CHANGE: 大幅优化`proxy`核心模块, 使用Chuncked Buffer传输数据, 减少内存占用
|
||||
|
||||
v1.8.3
|
||||
---
|
||||
- RELEASE: v1.8.3, 此版本作为v1.8.2的依赖更新版本(在v2发布前, v1仍会进行漏洞修复)
|
||||
- CHANGE: 更新Go版本至`1.23.5`以解决CVE漏洞
|
||||
|
||||
25w04b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2的候选版本(技术验证版),请勿在生产环境中使用; 我们可能会撤除v2更新计划(若技术验证版顺利通过, 则会发布v2正式版)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
25w04b
|
||||
25w04c
|
||||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
1.8.2
|
||||
1.8.3
|
||||
5
main.go
5
main.go
|
|
@ -91,11 +91,16 @@ func setupRateLimit(cfg *config.Config) {
|
|||
}
|
||||
}
|
||||
|
||||
func initBufferSize() {
|
||||
proxy.InitChunkedBufferSize(cfg.Server.BufferSize)
|
||||
}
|
||||
|
||||
func init() {
|
||||
readFlag()
|
||||
flag.Parse()
|
||||
loadConfig()
|
||||
setupLogger(cfg)
|
||||
initBufferSize()
|
||||
loadlist(cfg)
|
||||
setupRateLimit(cfg)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,16 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var chunkedBufferSize int
|
||||
|
||||
func InitChunkedBufferSize(cfgBufferSize int) {
|
||||
if cfgBufferSize == 0 {
|
||||
chunkedBufferSize = 4096 // 默认缓冲区大小
|
||||
} else {
|
||||
chunkedBufferSize = cfgBufferSize
|
||||
}
|
||||
}
|
||||
|
||||
func ChunkedProxyRequest(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)
|
||||
|
|
@ -72,14 +82,14 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri
|
|||
CopyResponseHeaders(resp, c, cfg)
|
||||
|
||||
c.Status(resp.StatusCode)
|
||||
if err := chunkedCopyResponseBody(c, cfg, resp.Body); err != nil {
|
||||
if err := chunkedCopyResponseBody(c, resp.Body); err != nil {
|
||||
logError("%s %s %s %s %s 响应复制错误: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 复制响应体
|
||||
func chunkedCopyResponseBody(c *gin.Context, cfg *config.Config, respBody io.Reader) error {
|
||||
buf := make([]byte, cfg.Server.BufferSize)
|
||||
func chunkedCopyResponseBody(c *gin.Context, respBody io.Reader) error {
|
||||
buf := make([]byte, chunkedBufferSize)
|
||||
for {
|
||||
n, err := respBody.Read(buf)
|
||||
if n > 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue