webmcp

view framework/env/request/get_param.lua @ 368:56cb5ed5e692

Bugfix in request.set_absolute_baseurl and request.register_mime_type (use request.configure to allow call at configuration time)
author jbe
date Mon Jul 27 21:56:29 2015 +0200 (2015-07-27)
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 --//--

Impressum / About Us