Skip to content

Commit

Permalink
Update interceptor routes matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
levichevdmitry committed Oct 18, 2021
1 parent 87a4ae5 commit 4189451
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls for Pip.Services in Go Changelog

## <a name="1.4.5"></a> 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$"
## <a name="1.4.4"></a> 1.4.4 (2021-08-30)
### Bug fixing
* Fix retry mechnaism in REST client
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions services/HttpEndpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/services/DummyRestService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4189451

Please sign in to comment.