Skip to content

Commit

Permalink
Added method match check for cache, transform and header injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Buhr committed Feb 5, 2015
1 parent 4e6ed07 commit a9ebe92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions api_definition_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func (a *APISpec) IsURLAllowedAndIgnored(method, url string, RxPaths []URLSpec,
}

// CheckSpecMatchesStatus checks if a url spec has a specific status
func (a *APISpec) CheckSpecMatchesStatus(url string, RxPaths []URLSpec, mode URLStatus) (bool, interface{}) {
func (a *APISpec) CheckSpecMatchesStatus(url string, method interface{}, RxPaths []URLSpec, mode URLStatus) (bool, interface{}) {
// Check if ignored
for _, v := range RxPaths {
match := v.Spec.MatchString(url)
Expand All @@ -550,9 +550,13 @@ func (a *APISpec) CheckSpecMatchesStatus(url string, RxPaths []URLSpec, mode URL
case Cached:
return true, nil
case Transformed:
return true, v.TransformAction
if method != nil && method.(string) == v.TransformAction.TemplateMeta.Method {
return true, v.TransformAction
}
case HeaderInjected:
return true, v.InjectHeaders
if method != nil && method.(string) == v.InjectHeaders.Method {
return true, v.TransformAction
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion middleware_modify_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t *TransformHeaders) ProcessRequest(w http.ResponseWriter, r *http.Request
var found bool

_, versionPaths, _, _ := t.TykMiddleware.Spec.GetVersionData(r)
found, meta = t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, versionPaths, HeaderInjected)
found, meta = t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, HeaderInjected)
if found {
stat = StatusHeaderInjected
}
Expand Down
2 changes: 1 addition & 1 deletion middleware_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *RedisCacheMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Req
} else {
// New request checker, more targetted, less likely to fail
_, versionPaths, _, _ := m.TykMiddleware.Spec.GetVersionData(r)
found, _ := m.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, versionPaths, Cached)
found, _ := m.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, Cached)
if found {
stat = StatusCached
}
Expand Down
2 changes: 1 addition & 1 deletion middleware_transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (t *TransformMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Requ
var found bool

_, versionPaths, _, _ := t.TykMiddleware.Spec.GetVersionData(r)
found, meta = t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, versionPaths, Transformed)
found, meta = t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, Transformed)
if found {
stat = StatusTransform
}
Expand Down

0 comments on commit a9ebe92

Please sign in to comment.