Эх сурвалжийг харах

bug:修复URL传递RPCX参数读取不到问题

Cheng Jian 2 жил өмнө
parent
commit
421403bc99

+ 16 - 3
micro_gateway/gin/server.go

@@ -96,8 +96,8 @@ func wrapServiceHandler(handler ServiceHandler) gin.HandlerFunc {
 			r.Header.Set(XServicePath, servicePath)
 		}
 
-		servicePath := r.Header.Get(XServicePath)
-		messageID := r.Header.Get(XMessageID)
+		servicePath := getRpcxHeader(r, XServicePath)
+		messageID := getRpcxHeader(r, XMessageID)
 		wh := w.Header()
 		if messageID != "" {
 			wh.Set(XMessageID, messageID)
@@ -111,7 +111,7 @@ func wrapServiceHandler(handler ServiceHandler) gin.HandlerFunc {
 			xmeta = "tenant=" + tenant
 		}
 
-		serviceMethod := r.Header.Get(XServiceMethod)
+		serviceMethod := getRpcxHeader(r, XServiceMethod)
 		if serviceMethod != "" {
 			if xmeta != "" {
 				xmeta = xmeta + "&"
@@ -210,6 +210,19 @@ func wrapServiceHandler(handler ServiceHandler) gin.HandlerFunc {
 	}
 }
 
+func getRpcxHeader(r *http.Request, key string) string {
+	val := r.Header.Get(key)
+	if val != "" {
+		return val
+	} else {
+		if values, ok := r.URL.Query()[key]; ok && len(values) > 0 {
+			return values[0]
+		} else {
+			return ""
+		}
+	}
+}
+
 func (s *Server) Serve() error {
 	return s.g.Run(s.addr)
 }