diff --git a/router/dealer.go b/router/dealer.go index 965d9fe9..452bd64d 100644 --- a/router/dealer.go +++ b/router/dealer.go @@ -516,7 +516,7 @@ func (d *Dealer) matchProcedure(procedure wamp.URI) (*registration, bool) { // No exact match was found. So, search for a prefix or wildcard // match, and prefer the most specific math (longest matched pattern). // If there is a tie, then prefer the first longest prefix. - var matchCount int + matchCount := -1 // initialize matchCount to -1 to catch an empty registration. for pfxProc, pfxReg := range d.pfxProcRegMap { if procedure.PrefixMatch(pfxProc) { if len(pfxProc) > matchCount { @@ -526,6 +526,12 @@ func (d *Dealer) matchProcedure(procedure wamp.URI) (*registration, bool) { } } } + // according to the spec, we have to prefer prefix match over wildcard match: + // https://wamp-proto.org/static/rfc/draft-oberstet-hybi-crossbar-wamp.html#rfc.section.14.3.8.1.4.2 + if ok { + return reg, ok + } + for wcProc, wcReg := range d.wcProcRegMap { if procedure.WildcardMatch(wcProc) { if len(wcProc) > matchCount { @@ -621,6 +627,8 @@ func (d *Dealer) call(caller *session, msg *wamp.Call) { Details: wamp.Dict{}, Error: wamp.ErrOptionDisallowedDiscloseMe, }) + // don't continue a call when discloseMe was disallowed. + return } if callee.HasFeature(roleCallee, featureCallerIdent) { discloseCaller(caller, details) @@ -639,6 +647,11 @@ func (d *Dealer) call(caller *session, msg *wamp.Call) { } } + if reg.match != wamp.MatchExact { + // according to the spec, a router has to provide the actual procedure to the client. + details[wamp.OptProcedure] = msg.Procedure + } + d.calls[msg.Request] = caller invocationID := d.idGen.Next() d.invocations[invocationID] = &invocation{ diff --git a/router/dealer_test.go b/router/dealer_test.go index 4db6eef2..6fbb3e9d 100644 --- a/router/dealer_test.go +++ b/router/dealer_test.go @@ -962,7 +962,9 @@ func TestPatternBasedRegistration(t *testing.T) { &wamp.Register{ Request: 123, Procedure: testProcedureWC, - Options: wamp.Dict{"match": "wildcard"}, + Options: wamp.Dict{ + wamp.OptMatch: wamp.MatchWildcard, + }, }) rsp := <-callee.Recv() _, ok := rsp.(*wamp.Registered) diff --git a/wamp/options.go b/wamp/options.go index b8a9ec43..65c0f893 100644 --- a/wamp/options.go +++ b/wamp/options.go @@ -11,6 +11,7 @@ const ( OptInvoke = "invoke" OptMatch = "match" OptMode = "mode" + OptProcedure = "procedure" OptProgress = "progress" OptReceiveProgress = "receive_progress" OptTimeout = "timeout"