X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8176a4e0a101b097704a294ccc5e4aec8dad25df..92d7d779d4f0415d09f536d286972bd953e7b566:/lib/controller/router/request.go?ds=sidebyside diff --git a/lib/controller/router/request.go b/lib/controller/router/request.go index f9eb3e76d1..377f7243c0 100644 --- a/lib/controller/router/request.go +++ b/lib/controller/router/request.go @@ -27,9 +27,32 @@ func (rtr *router) loadRequestParams(req *http.Request, attrsKey string) (map[st return nil, httpError(http.StatusBadRequest, err) } params := map[string]interface{}{} + + // Load parameters from req.Form, which (after + // req.ParseForm()) includes the query string and -- when + // Content-Type is application/x-www-form-urlencoded -- the + // request body. for k, values := range req.Form { + // All of these form values arrive as strings, so we + // need some type-guessing to accept non-string + // inputs: + // + // Values for parameters that take ints (limit=1) or + // bools (include_trash=1) are parsed accordingly. + // + // "null" and "" are nil. + // + // Values that look like JSON objects, arrays, or + // strings are parsed as JSON. + // + // The rest are left as strings. for _, v := range values { switch { + case intParams[k]: + params[k], err = strconv.ParseInt(v, 10, 64) + if err != nil { + return nil, err + } case boolParams[k]: params[k] = stringToBool(v) case v == "null" || v == "": @@ -55,11 +78,6 @@ func (rtr *router) loadRequestParams(req *http.Request, attrsKey string) (map[st return nil, err } params[k] = j - case k == "limit" || k == "offset": - params[k], err = strconv.ParseInt(v, 10, 64) - if err != nil { - return nil, err - } default: params[k] = v } @@ -133,7 +151,13 @@ func (rtr *router) transcode(src interface{}, dst interface{}) error { return err } +var intParams = map[string]bool{ + "limit": true, + "offset": true, +} + var boolParams = map[string]bool{ + "distinct": true, "ensure_unique_name": true, "include_trash": true, "include_old_versions": true,