webmcp
annotate framework/env/request/get_param_strings.lua @ 438:ea8419658535
Another change to make <db_object>:try_save() work properly with "document_column"
(use "_col" proxy also for accessing self._col[primary_key.json_doc])
(use "_col" proxy also for accessing self._col[primary_key.json_doc])
author | jbe |
---|---|
date | Wed Jan 20 21:06:07 2016 +0100 (2016-01-20) |
parents | ffdd32b48296 |
children |
rev | line source |
---|---|
jbe@91 | 1 --[[-- |
jbe@91 | 2 params = |
jbe@222 | 3 request.get_param_strings{ |
jbe@279 | 4 method = method, -- "GET", "POST", or nil to query both (POST has precedence) |
jbe@222 | 5 include_internal = include_internal -- set to true to include also parameters starting with "_webmcp_" prefix |
jbe@222 | 6 } |
jbe@91 | 7 |
jbe@99 | 8 This function returns a table with all raw GET/POST parameters as strings or list of strings (except internal parameters like "_webmcp_path" or "_webmcp_id"). Modifications of the returned table have no side effects. |
jbe@91 | 9 |
jbe@91 | 10 --]]-- |
jbe@91 | 11 |
jbe@253 | 12 local function merge_params(tbl, params_list, include) |
jbe@357 | 13 for key, values in pairs(params_list) do |
jbe@222 | 14 if not include and string.match(key, "^_webmcp_") then |
jbe@221 | 15 -- do nothing |
jbe@221 | 16 elseif string.match(key, "%[%]$") then |
jbe@221 | 17 tbl[key] = table.new(values) |
jbe@221 | 18 else |
jbe@221 | 19 tbl[key] = values[1] |
jbe@221 | 20 end |
jbe@221 | 21 end |
jbe@221 | 22 end |
jbe@221 | 23 |
jbe@222 | 24 function request.get_param_strings(args) |
jbe@222 | 25 local method = nil |
jbe@222 | 26 local include = false |
jbe@222 | 27 if args then |
jbe@222 | 28 method = args.method |
jbe@356 | 29 include = args.include_internal |
jbe@222 | 30 end |
jbe@99 | 31 local t = {} |
jbe@222 | 32 if not method then |
jbe@222 | 33 merge_params(t, request._http_request.get_params_list, include) |
jbe@222 | 34 merge_params(t, request._http_request.post_params_list, include) |
jbe@222 | 35 elseif method == "GET" then |
jbe@222 | 36 merge_params(t, request._http_request.get_params_list, include) |
jbe@222 | 37 elseif method == "POST" then |
jbe@222 | 38 merge_params(t, request._http_request.post_params_list, include) |
jbe@222 | 39 else |
jbe@222 | 40 error("Invalid method passed to request.get_param_strings{...}") |
jbe@222 | 41 end |
jbe@99 | 42 return t |
jbe@91 | 43 end |