webmcp

annotate framework/env/request/redirect.lua @ 567:5e3ebe9fd0ce

Added tag v2.2.1 for changeset 3b71fdb3a00d
author jbe
date Wed Apr 28 13:07:52 2021 +0200 (2021-04-28)
parents e2389cc82214
children
rev   line source
jbe/bsw@0 1 --[[--
jbe/bsw@0 2 request.redirect{
jbe@454 3 external = external, -- external URL (instead of specifying base, module, etc. below)
jbe@454 4 base = base, -- optional string containing a base URL of a WebMCP application
jbe@454 5 static = static, -- an URL relative to the static file directory
jbe@454 6 module = module, -- a module name of the WebMCP application
jbe@454 7 view = view, -- a view name of the WebMCP application
jbe@454 8 action = action, -- an action name of the WebMCP application
jbe@454 9 id = id, -- optional id to be passed to the view or action to select a particular data record
jbe@454 10 params = params, -- optional parameters to be passed to the view or action
jbe@454 11 anchor = anchor, -- anchor in URL
jbe@455 12 include_tempstore = include_tempstore -- set to true to include slot data via _tempstore param (defaults to true unless external is set)
jbe/bsw@0 13 }
jbe/bsw@0 14
jbe/bsw@0 15 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 16
jbe/bsw@0 17 --]]--
jbe/bsw@0 18
jbe/bsw@0 19 function request.redirect(args)
jbe@267 20 args = table.new(args)
jbe@267 21 if type(args.external) ~= "string" and type(args.static) ~= "string" then
jbe@267 22 if type(args.module) ~= "string" then
jbe@267 23 error("No module string passed to request.redirect{...}.")
jbe@267 24 end
jbe@267 25 if type(args.view) ~= "string" then
jbe@267 26 error("No view string passed to request.redirect{...}.")
jbe@267 27 end
jbe@276 28 if args.params ~= nil and type(args.params) ~= "table" then
jbe@267 29 error("Params array passed to request.redirect{...} is not a table.")
jbe@267 30 end
jbe@276 31 if args.anchor ~= nil and type(args.anchor) ~= "string" then
jbe@267 32 error("Anchor passed to request.redirect{...} must be a string or nil.")
jbe@267 33 end
jbe@113 34 end
jbe/bsw@0 35 if request.is_rerouted() then
jbe/bsw@0 36 error("Tried to redirect after another forward or redirect.")
jbe/bsw@0 37 end
jbe@267 38 request._redirect = args
jbe@267 39 if args.module and args.view then -- TODO: support for external redirects
jbe@267 40 trace.redirect{ module = args.module, view = args.view }
jbe@267 41 end
jbe/bsw@0 42 end

Impressum / About Us