mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
add bufferSize config
This commit is contained in:
parent
304c1cc184
commit
18000b94fb
3 changed files with 10 additions and 8 deletions
|
|
@ -20,6 +20,7 @@ type ServerConfig struct {
|
||||||
Host string `toml:"host"`
|
Host string `toml:"host"`
|
||||||
SizeLimit int `toml:"sizeLimit"`
|
SizeLimit int `toml:"sizeLimit"`
|
||||||
EnableH2C string `toml:"enableH2C"`
|
EnableH2C string `toml:"enableH2C"`
|
||||||
|
BufferSize int `toml:"bufferSize"`
|
||||||
Debug bool `toml:"debug"`
|
Debug bool `toml:"debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ host = "127.0.0.1"
|
||||||
port = 8080
|
port = 8080
|
||||||
sizeLimit = 125 # MB
|
sizeLimit = 125 # MB
|
||||||
enableH2C = "on" # "on" or "off"
|
enableH2C = "on" # "on" or "off"
|
||||||
|
bufferSize = 4096 # Bytes
|
||||||
debug = false
|
debug = false
|
||||||
|
|
||||||
[pages]
|
[pages]
|
||||||
|
|
|
||||||
|
|
@ -72,14 +72,14 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri
|
||||||
CopyResponseHeaders(resp, c, cfg)
|
CopyResponseHeaders(resp, c, cfg)
|
||||||
|
|
||||||
c.Status(resp.StatusCode)
|
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)
|
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 {
|
func chunkedCopyResponseBody(c *gin.Context, cfg *config.Config, respBody io.Reader) error {
|
||||||
buf := make([]byte, 4096)
|
buf := make([]byte, cfg.Server.BufferSize)
|
||||||
for {
|
for {
|
||||||
n, err := respBody.Read(buf)
|
n, err := respBody.Read(buf)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue