webmcp

changeset 97:52305ec73d47

Fixed 404 treatment regarding _webmcp_path interface
author jbe
date Sun Oct 14 17:11:13 2012 +0200 (2012-10-14)
parents db4bf2e6513c
children c92bd1ec1130
files framework/cgi-bin/webmcp.lua framework/env/request/__init.lua framework/env/request/is_404.lua
line diff
     1.1 --- a/framework/cgi-bin/webmcp.lua	Wed Oct 10 18:41:11 2012 +0200
     1.2 +++ b/framework/cgi-bin/webmcp.lua	Sun Oct 14 17:11:13 2012 +0200
     1.3 @@ -281,8 +281,7 @@
     1.4        end
     1.5      end
     1.6  
     1.7 -    if cgi.params["_webmcp_404"] then
     1.8 -      request.force_absolute_baseurl()
     1.9 +    if request.is_404() then
    1.10        request.set_status("404 Not Found")
    1.11        if request.get_404_route() then
    1.12          request.forward(request.get_404_route())
     2.1 --- a/framework/env/request/__init.lua	Wed Oct 10 18:41:11 2012 +0200
     2.2 +++ b/framework/env/request/__init.lua	Sun Oct 14 17:11:13 2012 +0200
     2.3 @@ -3,6 +3,7 @@
     2.4  request._forward_processed = false
     2.5  request._redirect = nil
     2.6  request._absolute_baseurl = nil
     2.7 +request._is_404 = false
     2.8  request._404_route = nil
     2.9  request._force_absolute_baseurl = false
    2.10  request._perm_params = {}
    2.11 @@ -12,6 +13,10 @@
    2.12  request._params = {}
    2.13  local depth
    2.14  if cgi then  -- if-clause to support interactive mode
    2.15 +  if cgi.params._webmcp_404 then
    2.16 +    request.force_absolute_baseurl()
    2.17 +    request._is_404 = true
    2.18 +  end
    2.19    for key, value in pairs(cgi.params) do
    2.20      if not string.match(key, "^_webmcp_") then
    2.21        request._params[key] = value
    2.22 @@ -24,21 +29,18 @@
    2.23        if path == "" then
    2.24          request._module = "index"
    2.25          request._view   = "index"
    2.26 -        depth = 0
    2.27          return
    2.28        end
    2.29        module = string.match(path, "^([^/]+)/$")
    2.30        if module then
    2.31          request._module = module
    2.32          request._view   = "index"
    2.33 -        depth = 1
    2.34          return
    2.35        end
    2.36        module, action = string.match(path, "^([^/]+)/([^/.]+)$")
    2.37        if module then
    2.38          request._module = module
    2.39          request._action = action
    2.40 -        depth = 1
    2.41          return
    2.42        end
    2.43        module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
    2.44 @@ -46,7 +48,6 @@
    2.45          request._module = module
    2.46          request._view   = view
    2.47          request._suffix = suffix
    2.48 -        depth = 1
    2.49          return
    2.50        end
    2.51        module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
    2.52 @@ -55,11 +56,15 @@
    2.53          request._view   = view
    2.54          request._id     = id
    2.55          request._suffix = suffix
    2.56 -        depth = 2
    2.57          return
    2.58        end
    2.59 +      request._is_404 = true
    2.60      end
    2.61      parse()
    2.62 +    depth = 0
    2.63 +    for match in string.gmatch(path, "/") do
    2.64 +      depth = depth + 1
    2.65 +    end
    2.66    else
    2.67      request._module = cgi.params._webmcp_module
    2.68      request._action = cgi.params._webmcp_action
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/framework/env/request/is_404.lua	Sun Oct 14 17:11:13 2012 +0200
     3.3 @@ -0,0 +1,11 @@
     3.4 +--[[--
     3.5 +is_404 =          -- boolean
     3.6 +request.is_404()
     3.7 +
     3.8 +Returns true, if this request results in a 404, else false.
     3.9 +
    3.10 +--]]--
    3.11 +
    3.12 +function request.is_404()
    3.13 +  return request._is_404
    3.14 +end

Impressum / About Us