From 4e786fee31dea5ead7b7d831e7f98467dca6341d Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 5 Jun 2023 18:35:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A5=E5=BF=97=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E8=A7=A3=E5=8E=8B=E6=96=B9=E5=BC=8F=E5=88=A4=E6=96=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20(#1260)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/middleware/operation.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/backend/middleware/operation.go b/backend/middleware/operation.go index 3be2cf389..f13471326 100644 --- a/backend/middleware/operation.go +++ b/backend/middleware/operation.go @@ -130,21 +130,24 @@ func OperationLog() gin.HandlerFunc { c.Next() - buf := bytes.NewReader(writer.body.Bytes()) - reader, err := gzip.NewReader(buf) - if err != nil { - record.Status = constant.StatusFailed - record.Message = fmt.Sprintf("gzip new reader failed, err: %v", err) - latency := time.Since(now) - record.Latency = latency + datas := writer.body.Bytes() + if c.Request.Header.Get("Content-Encoding") == "gzip" { + buf := bytes.NewReader(writer.body.Bytes()) + reader, err := gzip.NewReader(buf) + if err != nil { + record.Status = constant.StatusFailed + 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 { - global.LOG.Errorf("create operation record failed, err: %v", err) + if err := service.NewILogService().CreateOperationLog(record); err != nil { + 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 _ = json.Unmarshal(datas, &res) if res.Code == 200 {