From dad9aacffad4d53b2847be6b2f07ccb49ae007a7 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 11 Apr 2023 19:12:09 +0800 Subject: [PATCH] =?UTF-8?q?[ISSUE=20#1077]=20fix:http=20=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E6=8E=A5=E5=8F=A3=E9=89=B4=E6=9D=83=E8=A1=8C=E4=B8=BA?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E5=92=8CgRPC=E4=B8=80=E8=87=B4=20(#1076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix issue #629 (#693) * docs:优化错误信息描述 * Update zh.toml * fix:修复eureka心跳协议错误码不兼容问题 * fix:修复eureka心跳协议错误码不兼容问题 * unit:添加单元测试 * test:调整测试配置文件位置 * fix:issue #692 * fix:issue #692 * fix:issue #692 * fix:issue #692 * docs:add error code desc * fix:调整license-checker的触发 * fix:调整license-checker的触发 * fix:http 客户端接口鉴权凭据获取 --- apiserver/httpserver/v1/naming_client_access.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apiserver/httpserver/v1/naming_client_access.go b/apiserver/httpserver/v1/naming_client_access.go index 0e462c936..2faaecabc 100644 --- a/apiserver/httpserver/v1/naming_client_access.go +++ b/apiserver/httpserver/v1/naming_client_access.go @@ -18,6 +18,7 @@ package v1 import ( + "context" "fmt" "github.com/emicklei/go-restful/v3" @@ -109,6 +110,10 @@ func (h *HTTPServerV1) RegisterInstance(req *restful.Request, rsp *restful.Respo handler.WriteHeaderAndProto(api.NewResponseWithMsg(apimodel.Code_ParseException, err.Error())) return } + // 客户端请求中带了 token 的,优先已请求中的为准 + if instance.GetServiceToken().GetValue() != "" { + ctx = context.WithValue(ctx, utils.ContextAuthTokenKey, instance.GetServiceToken().GetValue()) + } handler.WriteHeaderAndProto(h.namingServer.RegisterInstance(ctx, instance)) } @@ -126,7 +131,10 @@ func (h *HTTPServerV1) DeregisterInstance(req *restful.Request, rsp *restful.Res handler.WriteHeaderAndProto(api.NewResponseWithMsg(apimodel.Code_ParseException, err.Error())) return } - + // 客户端请求中带了 token 的,优先已请求中的为准 + if instance.GetServiceToken().GetValue() != "" { + ctx = context.WithValue(ctx, utils.ContextAuthTokenKey, instance.GetServiceToken().GetValue()) + } handler.WriteHeaderAndProto(h.namingServer.DeregisterInstance(ctx, instance)) }