Explorar o código

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

Cheng Jian %!s(int64=2) %!d(string=hai) anos
pai
achega
421403bc99
Modificáronse 1 ficheiros con 16 adicións e 3 borrados
  1. 16 3
      micro_gateway/gin/server.go

+ 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)
 }