diff --git a/context.go b/context.go index d99ad16..147e310 100644 --- a/context.go +++ b/context.go @@ -260,6 +260,11 @@ func (ctx *Context) Params(name string) string { return ctx.params[name] } +// AllParams returns all params. +func (ctx *Context) AllParams() Params { + return ctx.params +} + // SetParams sets value of param with given name. func (ctx *Context) SetParams(name, val string) { if name != "*" && !strings.HasPrefix(name, ":") { diff --git a/context_test.go b/context_test.go index 051a93a..c1417d7 100644 --- a/context_test.go +++ b/context_test.go @@ -20,6 +20,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "sort" "strings" "testing" "time" @@ -171,6 +172,23 @@ func Test_Context(t *testing.T) { So(resp.Body.String(), ShouldEqual, "user user 1 13 1.24 ") }) + Convey("Get all URL paramaters", func() { + m.Get("/:arg/:param/:flag", func(ctx *Context) string { + kvs := make([]string, 0, len(ctx.AllParams())) + for k, v := range ctx.AllParams() { + kvs = append(kvs, k + "=" + v) + } + sort.Strings(kvs) + return strings.Join(kvs, ",") + }) + + resp := httptest.NewRecorder() + req, err := http.NewRequest("GET", "/1/2/3", nil) + So(err, ShouldBeNil) + m.ServeHTTP(resp,req) + So(resp.Body.String(), ShouldEqual, ":arg=1,:flag=3,:param=2") + }) + Convey("Get file", func() { m.Post("/getfile", func(ctx *Context) { ctx.Query("")