webmcp

view framework/env/request/__init.lua @ 101:dd21d2e06a95

In case of WebMCP based URL path parsing: Allow id to also be set by "_webmcp_id" parameter
author jbe
date Mon Oct 15 17:44:30 2012 +0200 (2012-10-15)
parents 52305ec73d47
children 47ebf4213716
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 -- allow id to also be set by "_webmcp_id" parameter
65 if cgi.params._webmcp_id ~= nil then
66 request._id = cgi.params._webmcp_id
67 end
68 depth = 0
69 for match in string.gmatch(path, "/") do
70 depth = depth + 1
71 end
72 else
73 request._module = cgi.params._webmcp_module
74 request._action = cgi.params._webmcp_action
75 request._view = cgi.params._webmcp_view
76 request._suffix = cgi.params._webmcp_suffix
77 request._id = cgi.params._webmcp_id
78 depth = tonumber(cgi.params._webmcp_urldepth)
79 end
80 end
81 if depth and depth > 0 then
82 local elements = {}
83 for i = 1, depth do
84 elements[#elements+1] = "../"
85 end
86 request._relative_baseurl = table.concat(elements)
87 else
88 request._relative_baseurl = "./"
89 end
91 request._app_basepath = assert(
92 os.getenv("WEBMCP_APP_BASEPATH"),
93 'WEBMCP_APP_BASEPATH is not set.'
94 )
95 if not string.find(request._app_basepath, "/$") then
96 request._app_basebase = request._app_basepath .. "/"
97 end

Impressum / About Us