From a9ebe92bfc413376a0a94c16f06f6b0c465c6a89 Mon Sep 17 00:00:00 2001 From: Martin Buhr Date: Thu, 5 Feb 2015 15:20:05 +0000 Subject: [PATCH] Added method match check for cache, transform and header injection --- api_definition_manager.go | 10 +++++++--- middleware_modify_headers.go | 2 +- middleware_redis_cache.go | 2 +- middleware_transform.go | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/api_definition_manager.go b/api_definition_manager.go index 9e546857af8..9f2148b0e0e 100644 --- a/api_definition_manager.go +++ b/api_definition_manager.go @@ -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) @@ -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 + } } } } diff --git a/middleware_modify_headers.go b/middleware_modify_headers.go index 3cc5ceb9db5..77f6a779fab 100644 --- a/middleware_modify_headers.go +++ b/middleware_modify_headers.go @@ -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 } diff --git a/middleware_redis_cache.go b/middleware_redis_cache.go index e8ae532e4f9..201682ad7fb 100644 --- a/middleware_redis_cache.go +++ b/middleware_redis_cache.go @@ -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 } diff --git a/middleware_transform.go b/middleware_transform.go index 6a5001fe7d3..24517930c63 100644 --- a/middleware_transform.go +++ b/middleware_transform.go @@ -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 }