From 41894510c2b10dfc6af683edeb66665e5753c725 Mon Sep 17 00:00:00 2001 From: Levichev Dmitry Date: Mon, 18 Oct 2021 22:15:48 +0300 Subject: [PATCH] Update interceptor routes matcher --- CHANGELOG.md | 8 ++++++++ component.json | 2 +- services/HttpEndpoint.go | 5 +++-- test/services/DummyRestService.go | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aebc14..5cf2fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Pip.Services Logo
Remote Procedure Calls for Pip.Services in Go Changelog +## 1.5.0 (2021-10-18) +### Features +* Added regexp supporting to interceptor + Examples: + - the interceptor route **"/dummies"** corresponds to all of this routes **"/dummies"**, **"/dummies/check"**, **"/dummies/test"** + - the interceptor route **"/dummies$"** corresponds only for this route **"/dummies"**. The routes **"/dummies/check"**, **"/dummies/test"** aren't processing by interceptor + Please, don't forgot, route in interceptor always automaticaly concateneted with base route, like this **service_base_route + route_in_interceptor**. + For example, "/api/v1/" - service base route, "/dummies$" - interceptor route, in result will be next expression - "/api/v1/dummies$" ## 1.4.4 (2021-08-30) ### Bug fixing * Fix retry mechnaism in REST client diff --git a/component.json b/component.json index 5cacae8..91c4fce 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "pip-services3-rpc-go", "registry": "github.com/pip-services3-go", - "version": "1.4.4", + "version": "1.5.0", "build": 0 } \ No newline at end of file diff --git a/services/HttpEndpoint.go b/services/HttpEndpoint.go index 3f4ea6e..b2372d9 100644 --- a/services/HttpEndpoint.go +++ b/services/HttpEndpoint.go @@ -6,6 +6,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "regexp" "strconv" "strings" "time" @@ -416,8 +417,8 @@ func (c *HttpEndpoint) RegisterInterceptor(route string, action func(w http.Resp route = c.fixRoute(route) interceptorFunc := func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - - if route != "" && r.URL.Path != route { + matched, _ := regexp.MatchString(route, r.URL.Path) + if route != "" && !matched { next.ServeHTTP(w, r) } else { action(w, r, next.ServeHTTP) diff --git a/test/services/DummyRestService.go b/test/services/DummyRestService.go index 68caade..62374b0 100644 --- a/test/services/DummyRestService.go +++ b/test/services/DummyRestService.go @@ -169,7 +169,7 @@ func (c *DummyRestService) checkErrorPropagation(res http.ResponseWriter, req *h } func (c *DummyRestService) Register() { - c.RegisterInterceptor("/dummies", c.incrementNumberOfCalls) + c.RegisterInterceptor("/dummies$", c.incrementNumberOfCalls) c.RegisterRoute( "get", "/dummies",