2025-04-03 17:31:43: merge [master:03df79d7b37febb99439347c2da79707bf437498];
This commit is contained in:
1 parent
1dd566593e
commit
64373fdf3c
9 files changed
+127
-100
No files matched your search
+10
-5
@@ -68,10 +68,12 @@ func (p Grpc) Handle(ctx *request.Context) error {
|
||||
return errors.WithMessage(err, "grpc: read body")
|
||||
}
|
||||
|
||||
requestId := requestid.FromContext(ctx.Context())
|
||||
md := metadata.MD{
|
||||
grpc.ProxyMethodNameHeader: {ctx.Endpoint()},
|
||||
requestid.RequestIdHeader: {requestid.FromContext(ctx.Context())},
|
||||
requestid.Header: {requestId},
|
||||
}
|
||||
|
||||
if !p.skipAuth {
|
||||
authData, err := ctx.GetAuthData()
|
||||
if err != nil {
|
||||
@@ -96,7 +98,7 @@ func (p Grpc) Handle(ctx *request.Context) error {
|
||||
return p.handleError(err, ctx.ResponseWriter())
|
||||
}
|
||||
|
||||
return p.writeResponse(http.StatusOK, result.GetBytesBody(), ctx.ResponseWriter())
|
||||
return p.writeResponse(http.StatusOK, result.GetBytesBody(), requestId, ctx.ResponseWriter())
|
||||
}
|
||||
|
||||
func (p Grpc) handleError(err error, w http.ResponseWriter) error {
|
||||
@@ -115,7 +117,7 @@ func (p Grpc) handleError(err error, w http.ResponseWriter) error {
|
||||
case *isp.Message:
|
||||
switch {
|
||||
case typeOfDetail.GetBytesBody() != nil:
|
||||
return p.writeResponse(statusCode, typeOfDetail.GetBytesBody(), w)
|
||||
return p.writeResponse(statusCode, typeOfDetail.GetBytesBody(), "", w)
|
||||
case typeOfDetail.GetListBody() != nil:
|
||||
return p.writeProto(statusCode, typeOfDetail.GetListBody(), w)
|
||||
case typeOfDetail.GetStructBody() != nil:
|
||||
@@ -138,11 +140,14 @@ func (p Grpc) writeProto(statusCode int, proto interface{}, w http.ResponseWrite
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "marshal grpc details to json")
|
||||
}
|
||||
return p.writeResponse(statusCode, data, w)
|
||||
return p.writeResponse(statusCode, data, "", w)
|
||||
}
|
||||
|
||||
func (p Grpc) writeResponse(statusCode int, data []byte, w http.ResponseWriter) error {
|
||||
func (p Grpc) writeResponse(statusCode int, data []byte, requestId string, w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
if requestId != "" {
|
||||
w.Header().Set(requestid.Header, requestId)
|
||||
}
|
||||
w.WriteHeader(statusCode)
|
||||
_, err := w.Write(data)
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ func (p Http) Handle(ctx *request.Context) error {
|
||||
}
|
||||
|
||||
func setHttpHeaders(ctx *request.Context, header http.Header, skipAuth bool) error {
|
||||
header.Set(requestid.RequestIdHeader, requestid.FromContext(ctx.Context()))
|
||||
header.Set(requestid.Header, requestid.FromContext(ctx.Context()))
|
||||
if !skipAuth {
|
||||
authData, err := ctx.GetAuthData()
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user