webmcp

view framework/env/request/__init.lua @ 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 dd21d2e06a95
line source
1 request._status = nil
2 request._forward = nil
3 request._forward_processed = false
4 request._redirect = nil
5 request._absolute_baseurl = nil
6 request._is_404 = false
7 request._404_route = nil
8 request._force_absolute_baseurl = false
9 request._perm_params = {}
10 request._csrf_secret = nil
11 request._json_requests_allowed = false
13 request._params = {}
14 local depth
15 if cgi then -- if-clause to support interactive mode
16 if cgi.params._webmcp_404 then
17 request.force_absolute_baseurl()
18 request._is_404 = true
19 end
20 for key, value in pairs(cgi.params) do
21 if not string.match(key, "^_webmcp_") then
22 request._params[key] = value
23 end
24 end
25 local path = cgi.params._webmcp_path
26 if path then
27 local function parse()
28 local module, action, view, suffix, id
29 if path == "" then
30 request._module = "index"
31 request._view = "index"
32 return
33 end
34 module = string.match(path, "^([^/]+)/$")
35 if module then
36 request._module = module
37 request._view = "index"
38 return
39 end
40 module, action = string.match(path, "^([^/]+)/([^/.]+)$")
41 if module then
42 request._module = module
43 request._action = action
44 return
45 end
46 module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
47 if module then
48 request._module = module
49 request._view = view
50 request._suffix = suffix
51 return
52 end
53 module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
54 if module then
55 request._module = module
56 request._view = view
57 request._id = id
58 request._suffix = suffix
59 return
60 end
61 request._is_404 = true
62 end
63 parse()
64 depth = 0
65 for match in string.gmatch(path, "/") do
66 depth = depth + 1
67 end
68 else
69 request._module = cgi.params._webmcp_module
70 request._action = cgi.params._webmcp_action
71 request._view = cgi.params._webmcp_view
72 request._suffix = cgi.params._webmcp_suffix
73 request._id = cgi.params._webmcp_id
74 depth = tonumber(cgi.params._webmcp_urldepth)
75 end
76 end
77 if depth and depth > 0 then
78 local elements = {}
79 for i = 1, depth do
80 elements[#elements+1] = "../"
81 end
82 request._relative_baseurl = table.concat(elements)
83 else
84 request._relative_baseurl = "./"
85 end
87 request._app_basepath = assert(
88 os.getenv("WEBMCP_APP_BASEPATH"),
89 'WEBMCP_APP_BASEPATH is not set.'
90 )
91 if not string.find(request._app_basepath, "/$") then
92 request._app_basebase = request._app_basepath .. "/"
93 end

Impressum / About Us