Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proxy-rewrite plugin in upstream #312

Merged
merged 1 commit into from
Jul 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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