add bufferSize config

This commit is contained in:
WJQSERVER 2025-01-18 08:49:19 +08:00
parent 304c1cc184
commit 18000b94fb
3 changed files with 10 additions and 8 deletions

View file

@ -16,11 +16,12 @@ type Config struct {
}
type ServerConfig struct {
Port int `toml:"port"`
Host string `toml:"host"`
SizeLimit int `toml:"sizeLimit"`
EnableH2C string `toml:"enableH2C"`
Debug bool `toml:"debug"`
Port int `toml:"port"`
Host string `toml:"host"`
SizeLimit int `toml:"sizeLimit"`
EnableH2C string `toml:"enableH2C"`
BufferSize int `toml:"bufferSize"`
Debug bool `toml:"debug"`
}
type PagesConfig struct {

View file

@ -3,6 +3,7 @@ host = "127.0.0.1"
port = 8080
sizeLimit = 125 # MB
enableH2C = "on" # "on" or "off"
bufferSize = 4096 # Bytes
debug = false
[pages]

View file

@ -72,14 +72,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, resp.Body); err != nil {
if err := chunkedCopyResponseBody(c, cfg, 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, respBody io.Reader) error {
buf := make([]byte, 4096)
func chunkedCopyResponseBody(c *gin.Context, cfg *config.Config, respBody io.Reader) error {
buf := make([]byte, cfg.Server.BufferSize)
for {
n, err := respBody.Read(buf)
if n > 0 {