1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

fix: 日志拦截解压方式判断修改 (#1260)

This commit is contained in:
ssongliu 2023-06-05 18:35:25 +08:00 committed by GitHub
parent 9f4e5050dd
commit 4e786fee31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,21 +130,24 @@ func OperationLog() gin.HandlerFunc {
c.Next() c.Next()
buf := bytes.NewReader(writer.body.Bytes()) datas := writer.body.Bytes()
reader, err := gzip.NewReader(buf) if c.Request.Header.Get("Content-Encoding") == "gzip" {
if err != nil { buf := bytes.NewReader(writer.body.Bytes())
record.Status = constant.StatusFailed reader, err := gzip.NewReader(buf)
record.Message = fmt.Sprintf("gzip new reader failed, err: %v", err) if err != nil {
latency := time.Since(now) record.Status = constant.StatusFailed
record.Latency = latency record.Message = fmt.Sprintf("gzip new reader failed, err: %v", err)
latency := time.Since(now)
record.Latency = latency
if err := service.NewILogService().CreateOperationLog(record); err != nil { if err := service.NewILogService().CreateOperationLog(record); err != nil {
global.LOG.Errorf("create operation record failed, err: %v", err) global.LOG.Errorf("create operation record failed, err: %v", err)
}
return
} }
return defer reader.Close()
datas, _ = io.ReadAll(reader)
} }
defer reader.Close()
datas, _ := io.ReadAll(reader)
var res response var res response
_ = json.Unmarshal(datas, &res) _ = json.Unmarshal(datas, &res)
if res.Code == 200 { if res.Code == 200 {