From cce0f2ede57cfe89451843ca802e65211a417a57 Mon Sep 17 00:00:00 2001 From: mark4z Date: Sat, 10 Jul 2021 22:44:51 +0800 Subject: [PATCH 1/2] update ratelimit samples Former-commit-id: bc883dd827624bf96d660479d53efadb71e016fd [formerly d2ada4888f3db5cad020b1fd795fe5ddc8871e17] Former-commit-id: 629338f354cd22228c87dc444ecb66cbc71c4244 --- samples/plugins/ratelimit/README.md | 2 +- samples/plugins/ratelimit/README_CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/plugins/ratelimit/README.md b/samples/plugins/ratelimit/README.md index 487136550..7c70c2844 100644 --- a/samples/plugins/ratelimit/README.md +++ b/samples/plugins/ratelimit/README.md @@ -37,7 +37,7 @@ resources: - enable: true flowRule: #the resource's name - resource: "test-dubbo" + resource: "test-http" threshold: 100 statintervalinms: 1000 ``` diff --git a/samples/plugins/ratelimit/README_CN.md b/samples/plugins/ratelimit/README_CN.md index 8c3995359..66aa1d073 100644 --- a/samples/plugins/ratelimit/README_CN.md +++ b/samples/plugins/ratelimit/README_CN.md @@ -34,7 +34,7 @@ resources: - enable: true flowRule: #the resource's name - resource: "test-dubbo" + resource: "test-http" threshold: 100 statintervalinms: 1000 ``` From dd84f2825427291489eeb2c8f2e84709e5170707 Mon Sep 17 00:00:00 2001 From: mark4z Date: Sun, 11 Jul 2021 21:02:02 +0800 Subject: [PATCH 2/2] make router case sensitive Former-commit-id: d788df60390c390b40654565525a61b873b67cfb [formerly cd62c74e41eea2009be09fe822c0faa3444ae9b3] Former-commit-id: 1cbfe7dd5fd526449bf47781916a3d3719ae83a9 --- pkg/router/route.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/router/route.go b/pkg/router/route.go index dcc3cd031..87959f9d4 100644 --- a/pkg/router/route.go +++ b/pkg/router/route.go @@ -61,22 +61,22 @@ func (rt *Route) ClearAPI() error { // PutAPI puts an api into the resource func (rt *Route) PutAPI(api router.API) error { - lowerCasePath := strings.ToLower(api.URLPattern) - node, ok := rt.findNode(lowerCasePath) + fullPath := api.URLPattern + node, ok := rt.findNode(fullPath) rt.lock.Lock() defer rt.lock.Unlock() if !ok { - wildcard := strings.Contains(lowerCasePath, constant.PathParamIdentifier) + wildcard := strings.Contains(fullPath, constant.PathParamIdentifier) rn := &Node{ - fullPath: lowerCasePath, + fullPath: fullPath, methods: map[config.HTTPVerb]*config.Method{api.Method.HTTPVerb: &api.Method}, wildcard: wildcard, headers: api.Headers, } if wildcard { - rt.wildcardTree.Put(lowerCasePath, rn) + rt.wildcardTree.Put(fullPath, rn) } - rt.tree.Put(lowerCasePath, rn) + rt.tree.Put(fullPath, rn) return nil } return node.putMethod(api.Method, api.Headers) @@ -122,10 +122,9 @@ func (rt *Route) FindAPI(fullPath string, httpverb config.HTTPVerb) (*router.API // DeleteNode delete node by fullPath func (rt *Route) DeleteNode(fullPath string) bool { - lowerPath := strings.ToLower(fullPath) rt.lock.RLock() defer rt.lock.RUnlock() - rt.tree.Remove(lowerPath) + rt.tree.Remove(fullPath) return true } @@ -141,13 +140,12 @@ func (rt *Route) DeleteAPI(fullPath string, httpverb config.HTTPVerb) bool { } func (rt *Route) findNode(fullPath string) (*Node, bool) { - lowerPath := strings.ToLower(fullPath) var n interface{} var found bool - if n, found = rt.searchWildcard(lowerPath); !found { + if n, found = rt.searchWildcard(fullPath); !found { rt.lock.RLock() defer rt.lock.RUnlock() - if n, found = rt.tree.Get(lowerPath); !found { + if n, found = rt.tree.Get(fullPath); !found { return nil, false } }