You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/07/12 14:25:20 UTC

[incubator-apisix-dashboard] branch master updated: fix: proxy-rewrite plugin in upstream (#312)

This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a87644  fix: proxy-rewrite plugin in upstream (#312)
3a87644 is described below

commit 3a87644f425c937d5637ea2fd24bcb76470545d4
Author: kv <gx...@163.com>
AuthorDate: Sun Jul 12 22:25:11 2020 +0800

    fix: proxy-rewrite plugin in upstream (#312)
---
 api/service/route.go | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/api/service/route.go b/api/service/route.go
index c99d0b7..fcb4a26 100644
--- a/api/service/route.go
+++ b/api/service/route.go
@@ -182,6 +182,9 @@ func (r *ApisixRouteResponse) Parse() (*RouteRequest, error) {
 	if o.Upstream != nil && o.Upstream.EnableWebsocket {
 		protocols = append(protocols, WEBSOCKET)
 	}
+	if o.UpstreamId != "" {
+		protocols = append(protocols, WEBSOCKET)
+	}
 	flag := true
 	for _, t := range o.Vars {
 		if t[0] == SCHEME {
@@ -221,7 +224,9 @@ func (r *ApisixRouteResponse) Parse() (*RouteRequest, error) {
 						upstreamProtocol = pr.Scheme
 					}
 					upstreamHeader = pr.Headers
-					if pr.RegexUri == nil || len(pr.RegexUri) < 2 {
+					if (pr.RegexUri == nil || len(pr.RegexUri) < 2) && pr.Uri == "" {
+						upstreamPath = nil
+					} else if pr.RegexUri == nil || len(pr.RegexUri) < 2 {
 						upstreamPath.UPathType = UPATHTYPE_STATIC
 						upstreamPath.To = pr.Uri
 					} else {
@@ -316,7 +321,7 @@ func (r Redirect) MarshalJSON() ([]byte, error) {
 	m := make(map[string]interface{})
 	if r.HttpToHttps {
 		m["http_to_https"] = true
-	} else {
+	} else if r.Uri != "" {
 		m["code"] = r.Code
 		m["uri"] = r.Uri
 	}
@@ -479,9 +484,10 @@ func ToApisixRequest(routeRequest *RouteRequest) *ApisixRouteRequest {
 	} else {
 		arr.Vars = nil
 	}
-
+	// upstreamId
+	arr.UpstreamId = routeRequest.UpstreamId
 	// upstream protocol
-	if arr.Upstream != nil {
+	if arr.Upstream != nil || arr.UpstreamId != "" {
 		pr := &ProxyRewrite{}
 		pr.Scheme = routeRequest.UpstreamProtocol
 		// upstream path
@@ -496,7 +502,7 @@ func ToApisixRequest(routeRequest *RouteRequest) *ApisixRouteRequest {
 		}
 		// upstream headers
 		pr.Headers = routeRequest.UpstreamHeader
-		if proxyPath != nil {
+		if proxyPath != nil || pr.Scheme != UPATHTYPE_KEEP || (pr.Headers != nil && len(pr.Headers) > 0) {
 			plugins[PROXY_REWRIETE] = pr
 		}
 	}
@@ -506,8 +512,7 @@ func ToApisixRequest(routeRequest *RouteRequest) *ApisixRouteRequest {
 	} else {
 		arr.Plugins = nil
 	}
-	// upstreamId
-	arr.UpstreamId = routeRequest.UpstreamId
+
 	return arr
 }