webmcp

diff framework/env/request/redirect.lua @ 267:56d237b81c18

Support for external redirects and redirects to static files
author jbe
date Fri Mar 20 15:12:31 2015 +0100 (2015-03-20)
parents ca88032cb37c
children bac6cbdeb055
line diff
     1.1 --- a/framework/env/request/redirect.lua	Fri Mar 20 13:41:28 2015 +0100
     1.2 +++ b/framework/env/request/redirect.lua	Fri Mar 20 15:12:31 2015 +0100
     1.3 @@ -1,10 +1,14 @@
     1.4  --[[--
     1.5  request.redirect{
     1.6 -  module = module,  -- module name
     1.7 -  view   = view,    -- view name
     1.8 -  id     = id,      -- optional id for view
     1.9 -  params = params,  -- optional view parameters
    1.10 -  anchor = anchor   -- anchor in URL
    1.11 +  external = external,   -- external URL (instead of specifying base, module, etc. below)
    1.12 +  base     = base,       -- optional string containing a base URL of a WebMCP application
    1.13 +  static   = static,     -- an URL relative to the static file directory
    1.14 +  module   = module,     -- a module name of the WebMCP application
    1.15 +  view     = view,       -- a view name of the WebMCP application
    1.16 +  action   = action,     -- an action name of the WebMCP application
    1.17 +  id       = id,         -- optional id to be passed to the view or action to select a particular data record
    1.18 +  params   = params,     -- optional parameters to be passed to the view or action
    1.19 +  anchor   = anchor      -- anchor in URL
    1.20  }
    1.21  
    1.22  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.
    1.23 @@ -12,34 +16,26 @@
    1.24  --]]--
    1.25  
    1.26  function request.redirect(args)
    1.27 -  -- TODO: support redirects to external URLs too
    1.28 -  --       (needs fixes in the trace system as well)
    1.29 -  local module = args.module
    1.30 -  local view   = args.view
    1.31 -  local id     = args.id
    1.32 -  local params = args.params or {}
    1.33 -  local anchor = args.anchor or nil
    1.34 -  if type(module) ~= "string" then
    1.35 -    error("No module string passed to request.redirect{...}.")
    1.36 -  end
    1.37 -  if type(view) ~= "string" then
    1.38 -    error("No view string passed to request.redirect{...}.")
    1.39 -  end
    1.40 -  if type(params) ~= "table" then
    1.41 -    error("Params array passed to request.redirect{...} is not a table.")
    1.42 -  end
    1.43 -  if anchor and type(anchor) ~= "string" then
    1.44 -    error("Anchor passed to request.redirect{...} must be a string or nil.")
    1.45 +  args = table.new(args)
    1.46 +  if type(args.external) ~= "string" and type(args.static) ~= "string" then
    1.47 +    if type(args.module) ~= "string" then
    1.48 +      error("No module string passed to request.redirect{...}.")
    1.49 +    end
    1.50 +    if type(args.view) ~= "string" then
    1.51 +      error("No view string passed to request.redirect{...}.")
    1.52 +    end
    1.53 +    if type(args.params) ~= "table" then
    1.54 +      error("Params array passed to request.redirect{...} is not a table.")
    1.55 +    end
    1.56 +    if args.anchor and type(args.anchor) ~= "string" then
    1.57 +      error("Anchor passed to request.redirect{...} must be a string or nil.")
    1.58 +    end
    1.59    end
    1.60    if request.is_rerouted() then
    1.61      error("Tried to redirect after another forward or redirect.")
    1.62    end
    1.63 -  request._redirect = {
    1.64 -    module = module,
    1.65 -    view   = view,
    1.66 -    id     = id,
    1.67 -    params = params,
    1.68 -    anchor = anchor
    1.69 -  }
    1.70 -  trace.redirect{ module = args.module, view = args.view }
    1.71 +  request._redirect = args
    1.72 +  if args.module and args.view then  -- TODO: support for external redirects
    1.73 +    trace.redirect{ module = args.module, view = args.view }
    1.74 +  end
    1.75  end

Impressum / About Us