Skip to content

Commit

Permalink
feature: strip path version from proxy upstream
Browse files Browse the repository at this point in the history
resolves: #492
  • Loading branch information
asoorm committed Feb 1, 2018
1 parent 0915506 commit 6ba77f7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,15 @@ func (a *APISpec) getVersionFromRequest(r *http.Request) string {
return r.URL.Query().Get(a.VersionDefinition.Key)

case "url":
url := strings.Replace(r.URL.Path, a.Proxy.ListenPath, "", 1)
uPath := strings.Replace(r.URL.Path, a.Proxy.ListenPath, "", 1)
// First non-empty part of the path is the version ID
for _, part := range strings.Split(url, "/") {
for _, part := range strings.Split(uPath, "/") {
if part != "" {

u := r.URL.String()
newU, _ := url.Parse(strings.Replace(u, part+"/", "", 1))
r.URL = newU

return part
}
}
Expand Down Expand Up @@ -1052,7 +1057,6 @@ func (a *APISpec) Version(r *http.Request) (*apidef.VersionInfo, []URLSpec, bool

// cache for the future
ctxSetVersionInfo(r, &version)

}

// Load path data and whitelist data for version
Expand All @@ -1070,7 +1074,6 @@ func (a *APISpec) Version(r *http.Request) (*apidef.VersionInfo, []URLSpec, bool
}

return &version, rxPaths, whiteListStatus, StatusOk

}

type RoundRobin struct {
Expand Down

0 comments on commit 6ba77f7

Please sign in to comment.