1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-19 09:56:02 +00:00
Former-commit-id: fe2dbe46ac8153ef4db0b5788794bf907b98baad
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-24 21:09:30 +03:00
parent baf68391b5
commit a4efb222cc
4 changed files with 23 additions and 7 deletions

View File

@@ -1909,8 +1909,6 @@ func (ctx *Context) ReadForm(formObject interface{}) error {
}
// ReadQuery binds url query to "ptr". The struct field tag is "url".
// If a client sent an unknown field, this method will return an error,
// in order to ignore that error use the `err != nil && !iris.IsErrPath(err)`.
//
// Example: https://github.com/kataras/iris/blob/master/_examples/request-body/read-query/main.go
func (ctx *Context) ReadQuery(ptr interface{}) error {
@@ -1980,6 +1978,16 @@ func (ctx *Context) ReadMsgPack(ptr interface{}) error {
// JSON, Protobuf, MsgPack, XML, YAML, MultipartForm and binds the result to the "ptr".
func (ctx *Context) ReadBody(ptr interface{}) error {
if ctx.Method() == http.MethodGet {
if ctx.Request().URL.RawQuery != "" {
// try read from query.
return ctx.ReadQuery(ptr)
}
// otherwise use the ReadForm,
// it's actually the same except
// ReadQuery will not fire errors on:
// 1. unknown or empty url query parameters
// 2. empty query or form (if FireEmptyFormError is enabled).
return ctx.ReadForm(ptr)
}