From dbf4b36687abea1582962a5413eb182966dbb5c7 Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Thu, 11 Mar 2021 21:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DrequestId=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/middleware/request_id.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/middleware/request_id.go b/common/middleware/request_id.go index 236bf44c..47161c34 100644 --- a/common/middleware/request_id.go +++ b/common/middleware/request_id.go @@ -1,6 +1,7 @@ package middleware import ( + "net/http" "strings" "github.com/gin-gonic/gin" @@ -10,6 +11,10 @@ import ( // RequestId 自动增加requestId func RequestId(trafficKey string) gin.HandlerFunc { return func(c *gin.Context) { + if c.Request.Method == http.MethodOptions { + c.Next() + return + } requestId := c.GetHeader(trafficKey) if requestId == "" { requestId = c.GetHeader(strings.ToLower(trafficKey)) @@ -17,7 +22,7 @@ func RequestId(trafficKey string) gin.HandlerFunc { if requestId == "" { requestId = uuid.New().String() } - c.Header(trafficKey, requestId) + c.Request.Header.Set(trafficKey, requestId) c.Set(trafficKey, requestId) c.Next() }