webmcp
view framework/env/request/get_param.lua @ 483:5b0066fd326e
Removed termination handling from WebMCP (to be done by moonbridge_io if needed)
| author | jbe | 
|---|---|
| date | Sun Jun 11 01:32:25 2017 +0200 (2017-06-11) | 
| parents | f60f5ee90efb | 
| children | 
 line source
     1 --[[--
     2 value =                 -- value of GET/POST parameter, or value list if multiple == true
     3 request.get_param{
     4   method   = method,    -- "GET", "POST", or nil to query both (POST has precedence)
     5   name     = name,      -- field name
     6   index    = index,     -- defaults to 1 to get first occurrence, only applicable if multiple == false
     7   multiple = multiple,  -- boolean to indicate whether to return a single value or a value list
     8   meta     = meta       -- set to true to get metadata (table with "file_name" and "content_type")
     9 }
    11 Reads GET/POST parameters directly from the underlaying request.
    13 --]]--
    15 function request.get_param(args)
    16   local param_list
    17   if args.metadata then
    18     if args.method == "GET" then
    19       error("HTTP GET parameters do not have metadata")
    20     elseif args.method == "POST" or not args.method then
    21       param_list = request._http_request.post_metadata_list[args.name]
    22     else
    23       error("Unknown HTTP method selected")
    24     end
    25   else
    26     if args.method == "GET" then
    27       param_list = request._http_request.get_params_list[args.name]
    28     elseif args.method == "POST" then
    29       param_list = request._http_request.post_params_list[args.name]
    30     elseif not args.method then
    31       param_list = request._http_request.post_params_list[args.name]
    32       if not param_list[args.index or 1] then
    33         param_list = request._http_request.get_params_list[args.name]
    34       end
    35     else
    36       error("Unknown HTTP method selected")
    37     end
    38   end
    39   if args.multiple then
    40     return param_list
    41   else
    42     return param_list[args.index or 1]
    43   end
    44 end
    46 --//--
