This commit is contained in:
2026-08-14 16:34:17 +08:00
parent e0b0e1d8c8
commit f63acae353
53 changed files with 2488 additions and 350 deletions
+17 -5
View File
@@ -10,12 +10,17 @@ import (
type captureWriter struct {
gin.ResponseWriter
body bytes.Buffer
body bytes.Buffer
maxBytes int
}
func (w *captureWriter) Write(data []byte) (int, error) {
if w.body.Len() < 32768 {
remaining := 32768 - w.body.Len()
limit := w.maxBytes
if limit <= 0 {
limit = 32768
}
if w.body.Len() < limit {
remaining := limit - w.body.Len()
if len(data) > remaining {
_, _ = w.body.Write(data[:remaining])
} else {
@@ -26,11 +31,18 @@ func (w *captureWriter) Write(data []byte) (int, error) {
}
func redactJSON(raw []byte) string {
return redactJSONLimit(raw, 32768)
}
func redactJSONLimit(raw []byte, limit int) string {
if len(raw) == 0 {
return ""
}
if len(raw) > 32768 {
raw = raw[:32768]
if limit <= 0 {
limit = 32768
}
if len(raw) > limit {
raw = raw[:limit]
}
var value any
if json.Unmarshal(raw, &value) != nil {