Skip to content

Commit

Permalink
Revert "Revert grpc-ecosystem#708 since it breaks backwards compatibi…
Browse files Browse the repository at this point in the history
…lity"

This reverts commit 60a328a.
  • Loading branch information
jfhamlin committed Jun 15, 2019
1 parent cddead4 commit f676703
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtime/mux.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package runtime

import (
"context"
"fmt"
"net/http"
"net/textproto"
"strings"
"context"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc/codes"
Expand Down
16 changes: 13 additions & 3 deletions runtime/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,30 @@ func TestMuxServeHTTP(t *testing.T) {
ops: []int{int(utilities.OpLitPush), 0, int(utilities.OpPush), 0, int(utilities.OpConcatN), 1, int(utilities.OpCapture), 1},
pool: []string{"foo", "id"},
},
},
reqMethod: "GET",
reqPath: "/foo/bar",
headers: map[string]string{
"Content-Type": "application/json",
},
respStatus: http.StatusOK,
respContent: "GET /foo/{id=*}",
},
{
patterns: []stubPattern{
{
method: "GET",
ops: []int{int(utilities.OpLitPush), 0, int(utilities.OpPush), 0, int(utilities.OpConcatN), 1, int(utilities.OpCapture), 1},
pool: []string{"foo", "id"},
verb: "verb",
},
},
reqMethod: "GET",
reqPath: "/foo/bar:verb",
reqPath: "/foo/bar:123",
headers: map[string]string{
"Content-Type": "application/json",
},
respStatus: http.StatusOK,
respContent: "GET /foo/{id=*}:verb",
respContent: "GET /foo/{id=*}",
},
{
// mux identifying invalid path results in 'Not Found' status
Expand Down
11 changes: 10 additions & 1 deletion runtime/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ 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
}
if len(components) == 0 {
components = []string{":" + verb}
} else {
components = append([]string{}, components...)
components[len(components)-1] += ":" + verb
}
verb = ""
}

var pos int
Expand Down

0 comments on commit f676703

Please sign in to comment.