webmcp
view framework/env/request/get_param_strings.lua @ 243:d5cba50e16ae
Send "Connection: close" header to terminate process
| author | jbe | 
|---|---|
| date | Sun Mar 01 20:52:03 2015 +0100 (2015-03-01) | 
| parents | 38e5399718ca | 
| children | 8f028a0aa114 | 
 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(include, tbl, params_list)
    13   for key, values in pairs(tbl) 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
    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
