This commit is contained in:
2026-08-16 15:11:38 +08:00
parent f7f6db8695
commit a85477be80
40 changed files with 761 additions and 144 deletions
+9 -3
View File
@@ -31,7 +31,10 @@ func OperationAudit(runtime *conf.Runtime, service *service.AuditRecorder) gin.H
}
if c.Request.Method == http.MethodGet {
requestBody = operationQueryBody(c.Request.URL.RawQuery)
} else if value, ok := c.Get(ctxReqBodyKey); ok {
requestBody = []byte(stringValue(value))
} else if c.Request.Body != nil {
// Fallback for tests or custom middleware chains that omit AccessLog.
if strings.Contains(c.GetHeader("Content-Type"), "multipart/form-data") {
requestBody = []byte("[文件]")
} else {
@@ -43,8 +46,6 @@ func OperationAudit(runtime *conf.Runtime, service *service.AuditRecorder) gin.H
// safety limit and only applies the configured operation-log limit when a
// download response is recorded. Using maxBytes here would silently
// truncate ordinary JSON responses before that decision is possible.
writer := &captureWriter{ResponseWriter: c.Writer, maxBytes: 1 << 20}
c.Writer = writer
started := time.Now()
c.Next()
userID := uint(0)
@@ -55,7 +56,12 @@ func OperationAudit(runtime *conf.Runtime, service *service.AuditRecorder) gin.H
}
requestID, _ := c.Get("request_id")
status := c.Writer.Status()
responseBody := writer.body.String()
responseBody := ""
if value, ok := c.Get(ctxRespBufferKey); ok {
if body, bok := value.(*bytes.Buffer); bok {
responseBody = body.String()
}
}
if isDownloadResponse(c) && len(responseBody) > maxBytes {
responseBody = "[超出记录长度]"
}