Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support url-encoded path parameters #567

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runtime/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (s *ServeMux) Handle(meth string, pat Pattern, h HandlerFunc) {
func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

path := r.URL.Path
path := r.URL.EscapedPath()

if !strings.HasPrefix(path, "/") {
if s.protoErrorHandler != nil {
_, outboundMarshaler := MarshalerForRequest(s, r)
Expand Down
31 changes: 31 additions & 0 deletions runtime/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestMuxServeHTTP(t *testing.T) {

respStatus int
respContent string
pathParams map[string]string
}{
{
patterns: nil,
Expand Down Expand Up @@ -176,6 +177,28 @@ func TestMuxServeHTTP(t *testing.T) {
respStatus: http.StatusOK,
respContent: "POST /foo:bar",
},
{
patterns: []stubPattern{
{
method: "GET",
ops: []int{
int(utilities.OpLitPush), 0,
int(utilities.OpLitPush), 1,
int(utilities.OpPush), 0,
int(utilities.OpConcatN), 1,
int(utilities.OpCapture), 2,
},
pool: []string{"v1", "bucket", "name"},
},
},
reqMethod: "GET",
reqPath: "/v1/bucket/my%2Fname",
respStatus: http.StatusOK,
respContent: "GET /v1/bucket/{name=*}",
pathParams: map[string]string{
"name": "my%2Fname",
},
},
} {
mux := runtime.NewServeMux()
for _, p := range spec.patterns {
Expand All @@ -186,7 +209,15 @@ func TestMuxServeHTTP(t *testing.T) {
}
mux.Handle(p.method, pat, func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
fmt.Fprintf(w, "%s %s", p.method, pat.String())

// Assert agains the expected path parameters
for name, value := range spec.pathParams {
if pathParams[name] != value {
t.Fatalf("expected pathParam %q to have value %q instead of %q", name, value, pathParams[name])
}
}
})

}(p)
}

Expand Down