webmcp

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

Impressum / About Us