Skip to content

Commit

Permalink
fix: proxy-rewrite plugin in upstream (apache#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxthrj authored Jul 12, 2020
1 parent 0c58fce commit 3a87644
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions api/service/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -506,8 +512,7 @@ func ToApisixRequest(routeRequest *RouteRequest) *ApisixRouteRequest {
} else {
arr.Plugins = nil
}
// upstreamId
arr.UpstreamId = routeRequest.UpstreamId

return arr
}

Expand Down

0 comments on commit 3a87644

Please sign in to comment.