webmcp

diff framework/env/request/__init.lua @ 91:2f8d8edd1836

URL parsing inside WebMCP to simplify webserver configuration
author jbe
date Wed Oct 10 17:41:46 2012 +0200 (2012-10-10)
parents 985024b16520
children db4bf2e6513c
line diff
     1.1 --- a/framework/env/request/__init.lua	Tue Aug 21 00:59:08 2012 +0200
     1.2 +++ b/framework/env/request/__init.lua	Wed Oct 10 17:41:46 2012 +0200
     1.3 @@ -9,8 +9,63 @@
     1.4  request._csrf_secret = nil
     1.5  request._json_requests_allowed = false
     1.6  
     1.7 +request._params = {}
     1.8  local depth
     1.9  if cgi then  -- if-clause to support interactive mode
    1.10 +  for key, value in pairs(cgi.params) do
    1.11 +    if not string.match(key, "^_webmcp_") then
    1.12 +      request._params[key] = value
    1.13 +    end
    1.14 +  end
    1.15 +  local path = cgi.params._webmcp_path
    1.16 +  if path then
    1.17 +    local function parse()
    1.18 +      local module, action, view, suffix, id
    1.19 +      if path == "" then
    1.20 +        request._module = "index"
    1.21 +        request._view   = "index"
    1.22 +        depth = 0
    1.23 +      end
    1.24 +      module = string.match(path, "^([^/]+)/$")
    1.25 +      if module then
    1.26 +        request._module = module
    1.27 +        request._view   = "index"
    1.28 +        depth = 1
    1.29 +        return
    1.30 +      end
    1.31 +      module, action = string.match(path, "^([^/]+)/([^/.]+)$")
    1.32 +      if module then
    1.33 +        request._module = module
    1.34 +        request._action = action
    1.35 +        depth = 1
    1.36 +        return
    1.37 +      end
    1.38 +      module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
    1.39 +      if module then
    1.40 +        request._module = module
    1.41 +        request._view   = view
    1.42 +        request._suffix = suffix
    1.43 +        depth = 1
    1.44 +        return
    1.45 +      end
    1.46 +      module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
    1.47 +      if module then
    1.48 +        request._module = module
    1.49 +        request._view   = view
    1.50 +        request._id     = id
    1.51 +        request._suffix = suffix
    1.52 +        depth = 2
    1.53 +        return
    1.54 +      end
    1.55 +    end
    1.56 +    parse()
    1.57 +  else
    1.58 +    request._module = cgi.params._webmcp_module
    1.59 +    request._action = cgi.params._webmcp_action
    1.60 +    request._view   = cgi.params._webmcp_view
    1.61 +    request._suffix = cgi.params._webmcp_suffix
    1.62 +    request._id     = cgi.params._webmcp_id
    1.63 +  end
    1.64    depth = tonumber(cgi.params._webmcp_urldepth)
    1.65  end
    1.66  if depth and depth > 0 then

Impressum / About Us