Skip to content

Commit

Permalink
Fix logic for non-matching path
Browse files Browse the repository at this point in the history
  • Loading branch information
Luan van Pletsen committed Mar 16, 2018
1 parent 7b79733 commit 75826d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 42 deletions.
50 changes: 12 additions & 38 deletions api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,9 @@ func (a APIDefinitionLoader) getPathSpecs(apiVersionDef apidef.VersionInfo) ([]U
}

func (a APIDefinitionLoader) generateRegex(stringSpec string, newSpec *URLSpec, specType URLStatus) {
// if strings.HasPrefix(stringSpec, "/") {
// stringSpec = stringSpec[1:]
// }
println("TEST")
apiLangIDsRegex := regexp.MustCompile(`{(.*?)}`)
asRegexStr := apiLangIDsRegex.ReplaceAllString(stringSpec, `(.*?)`)
asRegex, _ := regexp.Compile(asRegexStr)
println("asRegexStr")
println(asRegexStr)
println()
newSpec.Status = specType
newSpec.Spec = asRegex
}
Expand Down Expand Up @@ -904,54 +897,36 @@ func (a *APISpec) URLAllowedAndIgnored(r *http.Request, rxPaths []URLSpec, white

// CheckSpecMatchesStatus checks if a url spec has a specific status
func (a *APISpec) CheckSpecMatchesStatus(r *http.Request, rxPaths []URLSpec, mode URLStatus) (bool, interface{}) {
println("CheckSpecMatchesStatus")
// Check if ignored
for _, v := range rxPaths {
if mode != v.Status {
continue
}
println("----------------------")
println()
println("r.URL.Path")
println(r.URL.Path)
println("r.Method")
println(r.Method)
println("v.InjectHeadersResponse.Method")
println(v.InjectHeadersResponse.Method)
println("v.Status")
println(v.Status)
println("HeaderInjectedResponse")
println(HeaderInjectedResponse)
println("v.Spec.String()")
println(v.Spec.String())
println()

matchPath := r.URL.Path
if !strings.HasPrefix(matchPath, "/") {
matchPath = "/" + matchPath
}
match := v.Spec.MatchString(matchPath)
println("match")
println(match)

// only return it it's what we are looking for
if !match {
// check for special case when using url_rewrites with transform_response
// and specifying the same "path" expression
println("ctxGetUrlRewritePath(r)")
println(ctxGetUrlRewritePath(r))
println("v.InjectHeadersResponse.Path")
println(v.InjectHeadersResponse.Path)
println("mode")
println(mode)

if mode == TransformedResponse && v.TransformResponseAction.Path != ctxGetUrlRewritePath(r) {
continue
} else if mode == HeaderInjectedResponse && v.InjectHeadersResponse.Path != ctxGetUrlRewritePath(r) {

if mode == TransformedResponse {
if v.TransformResponseAction.Path != ctxGetUrlRewritePath(r) {
continue
}
} else if mode == HeaderInjectedResponse {
if v.InjectHeadersResponse.Path != ctxGetUrlRewritePath(r) {
continue
}
} else {
continue
}
}
}

switch v.Status {
case Ignored, BlackList, WhiteList, Cached:
return true, nil
Expand All @@ -964,7 +939,6 @@ func (a *APISpec) CheckSpecMatchesStatus(r *http.Request, rxPaths []URLSpec, mod
return true, &v.InjectHeaders
}
case HeaderInjectedResponse:
println(" case header injected response")
if r.Method == v.InjectHeadersResponse.Method {
return true, &v.InjectHeadersResponse
}
Expand Down
4 changes: 0 additions & 4 deletions reverse_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ func TykNewSingleHostReverseProxy(target *url.URL, spec *APISpec) *ReverseProxy
// if this is false, there was an url rewrite, thus we
// don't want to do anything to the path - req.URL is
// already final.
println("req.URL.Path before")
println(req.URL.Path)
if targetToUse == target {
req.URL.Scheme = targetToUse.Scheme
req.URL.Host = targetToUse.Host
Expand All @@ -241,8 +239,6 @@ func TykNewSingleHostReverseProxy(target *url.URL, spec *APISpec) *ReverseProxy
req.URL.RawPath = singleJoiningSlash(targetToUse.Path, req.URL.RawPath)
}
}
println("req.URL after")
println(req.URL.String())
if !spec.Proxy.PreserveHostHeader {
req.Host = targetToUse.Host
}
Expand Down

0 comments on commit 75826d0

Please sign in to comment.