From 1ac00250027f0587816b06dd9c2b820ac53d1efe Mon Sep 17 00:00:00 2001 From: askuy Date: Sun, 5 May 2024 18:32:32 +0800 Subject: [PATCH] fix header value --- server/egin/interceptor.go | 9 ++------- server/egrpc/interceptor.go | 10 ++-------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/server/egin/interceptor.go b/server/egin/interceptor.go index 6dd6bdf7..b1587dab 100644 --- a/server/egin/interceptor.go +++ b/server/egin/interceptor.go @@ -136,6 +136,7 @@ func (c *Container) defaultServerInterceptor() gin.HandlerFunc { var event = "normal" // 必须在defer外层,因为要赋值,替换ctx + // 只有在环境变量里的自定义header,才会写入到context value里 for _, key := range loggerKeys { // 赋值context getHeaderValue(ctx, key, c.config.EnableTrustedCustomHeader) @@ -416,13 +417,7 @@ func getHeaderValue(c *gin.Context, key string, enableTrustedCustomHeader bool) value := c.GetHeader(key) if value != "" { // 如果信任该Header,将header数据赋值到context上 - for _, customContextKey := range transport.CustomContextKeys() { - // 如果header key和自定义key是一样的,写入到contet value中 - if customContextKey == key { - c.Request = c.Request.WithContext(transport.WithValue(c.Request.Context(), key, value)) - } - } - + c.Request = c.Request.WithContext(transport.WithValue(c.Request.Context(), key, value)) } return value } diff --git a/server/egrpc/interceptor.go b/server/egrpc/interceptor.go index 8035e3da..4856c999 100644 --- a/server/egrpc/interceptor.go +++ b/server/egrpc/interceptor.go @@ -236,16 +236,10 @@ func (c *Container) defaultUnaryServerInterceptor() grpc.UnaryServerInterceptor var event = "normal" // 必须在defer外层,因为要赋值,替换ctx + // 只有在环境变量里的自定义header,才会写入到context value里 for _, key := range loggerKeys { if value := tools.GrpcHeaderValue(ctx, key); value != "" { - // 如果信任该Header,将header数据赋值到context上 - for _, customContextKey := range transport.CustomContextKeys() { - // 如果header key和自定义key是一样的,写入到contet value中 - if customContextKey == key { - ctx = transport.WithValue(ctx, key, value) - } - } - + ctx = transport.WithValue(ctx, key, value) } }