From 92019a638c9c6c34a21073bc3d5219a0133d6ffb Mon Sep 17 00:00:00 2001 From: James Hamlin Date: Tue, 24 Jul 2018 11:36:35 -0700 Subject: [PATCH] If a pattern has no verb, match with a verb arg appended to last component Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes #224 Signed-off-by: James Hamlin --- runtime/mux.go | 1 + runtime/pattern.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/mux.go b/runtime/mux.go index 1d4c75760fe..6c06ab8c222 100644 --- a/runtime/mux.go +++ b/runtime/mux.go @@ -7,6 +7,7 @@ import ( "strings" "context" + "github.com/golang/protobuf/proto" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" diff --git a/runtime/pattern.go b/runtime/pattern.go index f16a84ad389..b40f63fdfa1 100644 --- a/runtime/pattern.go +++ b/runtime/pattern.go @@ -144,7 +144,12 @@ func MustPattern(p Pattern, err error) Pattern { // If otherwise, the function returns an error. func (p Pattern) Match(components []string, verb string) (map[string]string, error) { if p.verb != verb { - return nil, ErrNotMatch + if p.verb != "" { + return nil, ErrNotMatch + } + components = append([]string{}, components...) + components[len(components)-1] += ":" + verb + verb = "" } var pos int