blob: 74ffc306c8e634b971cea67ab03f4e2c0d8efec1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
-- /usr/lib/cgit/lua/debug_gpgfrontend.lua
local r = lighty.r
local a = r.req_attr
-- Get the "original" path to avoid being affected by rewrites
local raw = a["uri.path-raw"] or a["uri.path"] or "/"
local orig = a["request.orig-uri"] or raw
-- Match two entry points:
-- 1) /GpgFrontend/...
-- 2) /cgit.cgi/GpgFrontend/... (when the user accessed cgit.cgi directly)
local new_path
if orig:match("^/GpgFrontend") then
new_path = orig:gsub("^/GpgFrontend", "/gpgfrontend")
elseif orig:match("^/cgit%.cgi/GpgFrontend") then
-- Convert /cgit.cgi/GpgFrontend/... to /gpgfrontend/... so rewrite adds /cgit.cgi only once
new_path = orig:gsub("^/cgit%.cgi/GpgFrontend", "/gpgfrontend")
end
if new_path then
local q = a["uri.query"]
if q and #q > 0 and not new_path:find("%?") then
new_path = new_path .. "?" .. q
end
r.resp_header["Location"] = new_path
return 301
end
r.resp_header["X-Magnet-Probed"] = "1"
return 0
|