webmcp
view framework/env/request/get_param_strings.lua @ 450:d7814e6d0124
Fixed error in error creation in execute._create_sorted_execution_list when two initializers have the same name
| author | jbe | 
|---|---|
| date | Thu Jul 21 12:46:10 2016 +0200 (2016-07-21) | 
| parents | ffdd32b48296 | 
| children | 
 line source
     1 --[[--
     2 params =
     3 request.get_param_strings{
     4   method           = method,           -- "GET", "POST", or nil to query both (POST has precedence)
     5   include_internal = include_internal  -- set to true to include also parameters starting with "_webmcp_" prefix
     6 }
     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.
    10 --]]--
    12 local function merge_params(tbl, params_list, include)
    13   for key, values in pairs(params_list) do
    14     if not include and string.match(key, "^_webmcp_") then
    15       -- do nothing
    16     elseif string.match(key, "%[%]$") then
    17       tbl[key] = table.new(values)
    18     else
    19       tbl[key] = values[1]
    20     end
    21   end
    22 end
    24 function request.get_param_strings(args)
    25   local method = nil
    26   local include = false
    27   if args then
    28     method  = args.method
    29     include = args.include_internal
    30   end
    31   local t = {}
    32   if not method then
    33     merge_params(t, request._http_request.get_params_list, include)
    34     merge_params(t, request._http_request.post_params_list, include)
    35   elseif method == "GET" then
    36     merge_params(t, request._http_request.get_params_list, include)
    37   elseif method == "POST" then
    38     merge_params(t, request._http_request.post_params_list, include)
    39   else
    40     error("Invalid method passed to request.get_param_strings{...}")
    41   end
    42   return t
    43 end
