fix
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user