请求明细支持查看原始请求/响应:OT_PROXY_LOG_RAW 开关控制,仅管理员记录与可见,流式全量捕获

- 配置: ProxyConfig.LogRaw (OT_PROXY_LOG_RAW, 默认 false)
- 存储: usage_logs 新增 raw_request/raw_response 文本列 (AutoMigrate)
- 网关: NewGateway 接收 logRaw 参数
- handlers: 三个协议入口按 开关+管理员 条件记录原始请求体
- passthrough: 非流式 copyAndCapture 捕获响应, 流式 streamCopy 累积全部原始 SSE 行, finishUsage 统一写入
- admin API: AdminUsage 返回 raw_request/raw_response (仅管理员)
- 前端: 用量页新增查看入口, 弹窗 tab 切换请求/响应
- gitignore: 修正 server/web/ 忽略规则(尾随空格导致未生效)
This commit is contained in:
Sakurasan
2026-08-20 00:37:48 +08:00
parent 0939f98fb5
commit 10f51cbdae
11 changed files with 111 additions and 4 deletions
+3 -1
View File
@@ -35,6 +35,7 @@ type Gateway struct {
enc *crypto.Encryptor
lim *ratelimit.Limiter
userRPS int
logRaw bool
hc *http.Client
policyMu sync.Mutex
@@ -108,7 +109,7 @@ func contains(list []string, s string) bool {
return false
}
func NewGateway(db *gorm.DB, enc *crypto.Encryptor, rec *usage.Recorder, lim *ratelimit.Limiter, userRPS int) *Gateway {
func NewGateway(db *gorm.DB, enc *crypto.Encryptor, rec *usage.Recorder, lim *ratelimit.Limiter, userRPS int, logRaw bool) *Gateway {
return &Gateway{
db: db,
ch: channel.NewService(db, enc),
@@ -116,6 +117,7 @@ func NewGateway(db *gorm.DB, enc *crypto.Encryptor, rec *usage.Recorder, lim *ra
enc: enc,
lim: lim,
userRPS: userRPS,
logRaw: logRaw,
hc: &http.Client{Timeout: 120 * time.Second},
}
}