Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
d04b47b3
Commit
d04b47b3
authored
Feb 14, 2026
by
yangjianbo
Browse files
feat(backend): 提交后端审计修复与配套测试改动
parent
86219914
Changes
22
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/upstream_response_limit_test.go
0 → 100644
View file @
d04b47b3
package
service
import
(
"bytes"
"errors"
"testing"
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/stretchr/testify/require"
)
func
TestResolveUpstreamResponseReadLimit
(
t
*
testing
.
T
)
{
t
.
Run
(
"use default when config missing"
,
func
(
t
*
testing
.
T
)
{
require
.
Equal
(
t
,
defaultUpstreamResponseReadMaxBytes
,
resolveUpstreamResponseReadLimit
(
nil
))
})
t
.
Run
(
"use configured value"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
&
config
.
Config
{}
cfg
.
Gateway
.
UpstreamResponseReadMaxBytes
=
1234
require
.
Equal
(
t
,
int64
(
1234
),
resolveUpstreamResponseReadLimit
(
cfg
))
})
}
func
TestReadUpstreamResponseBodyLimited
(
t
*
testing
.
T
)
{
t
.
Run
(
"within limit"
,
func
(
t
*
testing
.
T
)
{
body
,
err
:=
readUpstreamResponseBodyLimited
(
bytes
.
NewReader
([]
byte
(
"ok"
)),
2
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
[]
byte
(
"ok"
),
body
)
})
t
.
Run
(
"exceeds limit"
,
func
(
t
*
testing
.
T
)
{
body
,
err
:=
readUpstreamResponseBodyLimited
(
bytes
.
NewReader
([]
byte
(
"toolong"
)),
3
)
require
.
Nil
(
t
,
body
)
require
.
Error
(
t
,
err
)
require
.
True
(
t
,
errors
.
Is
(
err
,
ErrUpstreamResponseBodyTooLarge
))
})
}
deploy/config.example.yaml
View file @
d04b47b3
...
...
@@ -146,6 +146,15 @@ gateway:
# Max request body size in bytes (default: 100MB)
# 请求体最大字节数(默认 100MB)
max_body_size
:
104857600
# Max bytes to read for non-stream upstream responses (default: 8MB)
# 非流式上游响应体读取上限(默认 8MB)
upstream_response_read_max_bytes
:
8388608
# Max bytes to read for proxy probe responses (default: 1MB)
# 代理探测响应体读取上限(默认 1MB)
proxy_probe_response_read_max_bytes
:
1048576
# Enable Gemini upstream response header debug logs (default: false)
# 是否开启 Gemini 上游响应头调试日志(默认 false)
gemini_debug_response_headers
:
false
# Sora max request body size in bytes (0=use max_body_size)
# Sora 请求体最大字节数(0=使用 max_body_size)
sora_max_body_size
:
268435456
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment