webmcp

annotate framework/env/request/redirect.lua @ 401:ad437022be90

Quick fix to avoid problems on document creation
author jbe
date Mon Jan 04 00:48:47 2016 +0100 (2016-01-04)
parents bac6cbdeb055
children 4e03ecb28665
rev   line source
jbe/bsw@0 1 --[[--
jbe/bsw@0 2 request.redirect{
jbe@267 3 external = external, -- external URL (instead of specifying base, module, etc. below)
jbe@267 4 base = base, -- optional string containing a base URL of a WebMCP application
jbe@267 5 static = static, -- an URL relative to the static file directory
jbe@267 6 module = module, -- a module name of the WebMCP application
jbe@267 7 view = view, -- a view name of the WebMCP application
jbe@267 8 action = action, -- an action name of the WebMCP application
jbe@267 9 id = id, -- optional id to be passed to the view or action to select a particular data record
jbe@267 10 params = params, -- optional parameters to be passed to the view or action
jbe@267 11 anchor = anchor -- anchor in URL
jbe/bsw@0 12 }
jbe/bsw@0 13
jbe/bsw@0 14 Calling this function causes the WebMCP to do a 303 HTTP redirect after the current view or action and all filters have finished execution. If routing mode "redirect" has been chosen, then this function is called automatically after an action and all its filters have finished execution. Calling request.redirect{...} (or request.forward{...}) explicitly inside an action will cause routing information from the browser to be ignored. To preserve GET/POST parameters of an action, use request.forward{...} instead. Currently no redirects to external (absolute) URLs are possible, there will be an implementation in future though.
jbe/bsw@0 15
jbe/bsw@0 16 --]]--
jbe/bsw@0 17
jbe/bsw@0 18 function request.redirect(args)
jbe@267 19 args = table.new(args)
jbe@267 20 if type(args.external) ~= "string" and type(args.static) ~= "string" then
jbe@267 21 if type(args.module) ~= "string" then
jbe@267 22 error("No module string passed to request.redirect{...}.")
jbe@267 23 end
jbe@267 24 if type(args.view) ~= "string" then
jbe@267 25 error("No view string passed to request.redirect{...}.")
jbe@267 26 end
jbe@276 27 if args.params ~= nil and type(args.params) ~= "table" then
jbe@267 28 error("Params array passed to request.redirect{...} is not a table.")
jbe@267 29 end
jbe@276 30 if args.anchor ~= nil and type(args.anchor) ~= "string" then
jbe@267 31 error("Anchor passed to request.redirect{...} must be a string or nil.")
jbe@267 32 end
jbe@113 33 end
jbe/bsw@0 34 if request.is_rerouted() then
jbe/bsw@0 35 error("Tried to redirect after another forward or redirect.")
jbe/bsw@0 36 end
jbe@267 37 request._redirect = args
jbe@267 38 if args.module and args.view then -- TODO: support for external redirects
jbe@267 39 trace.redirect{ module = args.module, view = args.view }
jbe@267 40 end
jbe/bsw@0 41 end

Impressum / About Us