# HG changeset patch # User jbe # Date 1425053888 -3600 # Node ID 38e5399718cabf51a8059bf6a12a52a8b5fb28fb # Parent 25a20bd1f4161b60abb62e3e9b283cdf61f6fd57 Use request.get_param{...} and request.get_param_strings{...} functions in request.process() diff -r 25a20bd1f416 -r 38e5399718ca framework/env/request/get_param_strings.lua --- a/framework/env/request/get_param_strings.lua Wed Feb 25 01:33:27 2015 +0100 +++ b/framework/env/request/get_param_strings.lua Fri Feb 27 17:18:08 2015 +0100 @@ -1,14 +1,17 @@ --[[-- params = -request.get_param_strings() +request.get_param_strings{ + method = method -- "GET", "POST", or nil to query both (POST has precedence) + include_internal = include_internal -- set to true to include also parameters starting with "_webmcp_" prefix +} 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. --]]-- -local function merge_params(tbl, params_list) +local function merge_params(include, tbl, params_list) for key, values in pairs(tbl) do - if string.match(key, "^_webmcp_") then + if not include and string.match(key, "^_webmcp_") then -- do nothing elseif string.match(key, "%[%]$") then tbl[key] = table.new(values) @@ -18,9 +21,23 @@ end end -function request.get_param_strings() +function request.get_param_strings(args) + local method = nil + local include = false + if args then + method = args.method + include = args.include + end local t = {} - merge_params(t, request._http_request.get_params_list) - merge_params(t, request._http_request.post_params_list) + if not method then + merge_params(t, request._http_request.get_params_list, include) + merge_params(t, request._http_request.post_params_list, include) + elseif method == "GET" then + merge_params(t, request._http_request.get_params_list, include) + elseif method == "POST" then + merge_params(t, request._http_request.post_params_list, include) + else + error("Invalid method passed to request.get_param_strings{...}") + end return t end diff -r 25a20bd1f416 -r 38e5399718ca framework/env/request/process.lua --- a/framework/env/request/process.lua Wed Feb 25 01:33:27 2015 +0100 +++ b/framework/env/request/process.lua Fri Feb 27 17:18:08 2015 +0100 @@ -16,7 +16,7 @@ function() -- restore slots if coming from http redirect - local tempstore_value = request.get_param{method = "GET", name = "_tempstore"} + local tempstore_value = request._http_request.get_params["_tempstore"] if tempstore_value then trace.restore_slots{} local blob = tempstore.pop(tempstore_value) @@ -51,22 +51,22 @@ } if not request.is_rerouted() then local routing_mode, routing_module, routing_view - routing_mode = cgi.params["_webmcp_routing." .. action_status .. ".mode"] - routing_module = cgi.params["_webmcp_routing." .. action_status .. ".module"] - routing_view = cgi.params["_webmcp_routing." .. action_status .. ".view"] - routing_anchor = cgi.params["_webmcp_routing." .. action_status .. ".anchor"] + routing_mode = request._http_request.post_params["_webmcp_routing." .. action_status .. ".mode"] + routing_module = request._http_request.post_params["_webmcp_routing." .. action_status .. ".module"] + routing_view = request._http_request.post_params["_webmcp_routing." .. action_status .. ".view"] + routing_anchor = request._http_request.post_params["_webmcp_routing." .. action_status .. ".anchor"] if not (routing_mode or routing_module or routing_view) then action_status = "default" - routing_mode = cgi.params["_webmcp_routing.default.mode"] - routing_module = cgi.params["_webmcp_routing.default.module"] - routing_view = cgi.params["_webmcp_routing.default.view"] - routing_anchor = cgi.params["_webmcp_routing.default.anchor"] + routing_mode = request._http_request.post_params["_webmcp_routing.default.mode"] + routing_module = request._http_request.post_params["_webmcp_routing.default.module"] + routing_view = request._http_request.post_params["_webmcp_routing.default.view"] + routing_anchor = request._http_request.post_params["_webmcp_routing.default.anchor"] end assert(routing_module, "Routing information has no module.") assert(routing_view, "Routing information has no view.") if routing_mode == "redirect" then local routing_params = {} - for key, value in pairs(cgi.params) do + for key, value in request.get_param_strings{method="POST", include_internal=true} do local status, stripped_key = string.match( key, "^_webmcp_routing%.([^%.]*)%.params%.(.*)$" ) @@ -77,7 +77,7 @@ request.redirect{ module = routing_module, view = routing_view, - id = cgi.params["_webmcp_routing." .. action_status .. ".id"], + id = request._http_request.post_params["_webmcp_routing." .. action_status .. ".id"], params = routing_params, anchor = routing_anchor }