webmcp
changeset 222:38e5399718ca
Use request.get_param{...} and request.get_param_strings{...} functions in request.process()
author | jbe |
---|---|
date | Fri Feb 27 17:18:08 2015 +0100 (2015-02-27) |
parents | 25a20bd1f416 |
children | 32ec28229bb5 |
files | framework/env/request/get_param_strings.lua framework/env/request/process.lua |
line diff
1.1 --- a/framework/env/request/get_param_strings.lua Wed Feb 25 01:33:27 2015 +0100 1.2 +++ b/framework/env/request/get_param_strings.lua Fri Feb 27 17:18:08 2015 +0100 1.3 @@ -1,14 +1,17 @@ 1.4 --[[-- 1.5 params = 1.6 -request.get_param_strings() 1.7 +request.get_param_strings{ 1.8 + method = method -- "GET", "POST", or nil to query both (POST has precedence) 1.9 + include_internal = include_internal -- set to true to include also parameters starting with "_webmcp_" prefix 1.10 +} 1.11 1.12 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. 1.13 1.14 --]]-- 1.15 1.16 -local function merge_params(tbl, params_list) 1.17 +local function merge_params(include, tbl, params_list) 1.18 for key, values in pairs(tbl) do 1.19 - if string.match(key, "^_webmcp_") then 1.20 + if not include and string.match(key, "^_webmcp_") then 1.21 -- do nothing 1.22 elseif string.match(key, "%[%]$") then 1.23 tbl[key] = table.new(values) 1.24 @@ -18,9 +21,23 @@ 1.25 end 1.26 end 1.27 1.28 -function request.get_param_strings() 1.29 +function request.get_param_strings(args) 1.30 + local method = nil 1.31 + local include = false 1.32 + if args then 1.33 + method = args.method 1.34 + include = args.include 1.35 + end 1.36 local t = {} 1.37 - merge_params(t, request._http_request.get_params_list) 1.38 - merge_params(t, request._http_request.post_params_list) 1.39 + if not method then 1.40 + merge_params(t, request._http_request.get_params_list, include) 1.41 + merge_params(t, request._http_request.post_params_list, include) 1.42 + elseif method == "GET" then 1.43 + merge_params(t, request._http_request.get_params_list, include) 1.44 + elseif method == "POST" then 1.45 + merge_params(t, request._http_request.post_params_list, include) 1.46 + else 1.47 + error("Invalid method passed to request.get_param_strings{...}") 1.48 + end 1.49 return t 1.50 end
2.1 --- a/framework/env/request/process.lua Wed Feb 25 01:33:27 2015 +0100 2.2 +++ b/framework/env/request/process.lua Fri Feb 27 17:18:08 2015 +0100 2.3 @@ -16,7 +16,7 @@ 2.4 function() 2.5 2.6 -- restore slots if coming from http redirect 2.7 - local tempstore_value = request.get_param{method = "GET", name = "_tempstore"} 2.8 + local tempstore_value = request._http_request.get_params["_tempstore"] 2.9 if tempstore_value then 2.10 trace.restore_slots{} 2.11 local blob = tempstore.pop(tempstore_value) 2.12 @@ -51,22 +51,22 @@ 2.13 } 2.14 if not request.is_rerouted() then 2.15 local routing_mode, routing_module, routing_view 2.16 - routing_mode = cgi.params["_webmcp_routing." .. action_status .. ".mode"] 2.17 - routing_module = cgi.params["_webmcp_routing." .. action_status .. ".module"] 2.18 - routing_view = cgi.params["_webmcp_routing." .. action_status .. ".view"] 2.19 - routing_anchor = cgi.params["_webmcp_routing." .. action_status .. ".anchor"] 2.20 + routing_mode = request._http_request.post_params["_webmcp_routing." .. action_status .. ".mode"] 2.21 + routing_module = request._http_request.post_params["_webmcp_routing." .. action_status .. ".module"] 2.22 + routing_view = request._http_request.post_params["_webmcp_routing." .. action_status .. ".view"] 2.23 + routing_anchor = request._http_request.post_params["_webmcp_routing." .. action_status .. ".anchor"] 2.24 if not (routing_mode or routing_module or routing_view) then 2.25 action_status = "default" 2.26 - routing_mode = cgi.params["_webmcp_routing.default.mode"] 2.27 - routing_module = cgi.params["_webmcp_routing.default.module"] 2.28 - routing_view = cgi.params["_webmcp_routing.default.view"] 2.29 - routing_anchor = cgi.params["_webmcp_routing.default.anchor"] 2.30 + routing_mode = request._http_request.post_params["_webmcp_routing.default.mode"] 2.31 + routing_module = request._http_request.post_params["_webmcp_routing.default.module"] 2.32 + routing_view = request._http_request.post_params["_webmcp_routing.default.view"] 2.33 + routing_anchor = request._http_request.post_params["_webmcp_routing.default.anchor"] 2.34 end 2.35 assert(routing_module, "Routing information has no module.") 2.36 assert(routing_view, "Routing information has no view.") 2.37 if routing_mode == "redirect" then 2.38 local routing_params = {} 2.39 - for key, value in pairs(cgi.params) do 2.40 + for key, value in request.get_param_strings{method="POST", include_internal=true} do 2.41 local status, stripped_key = string.match( 2.42 key, "^_webmcp_routing%.([^%.]*)%.params%.(.*)$" 2.43 ) 2.44 @@ -77,7 +77,7 @@ 2.45 request.redirect{ 2.46 module = routing_module, 2.47 view = routing_view, 2.48 - id = cgi.params["_webmcp_routing." .. action_status .. ".id"], 2.49 + id = request._http_request.post_params["_webmcp_routing." .. action_status .. ".id"], 2.50 params = routing_params, 2.51 anchor = routing_anchor 2.52 }