jsproxy/lua/http-dec-req-hdr.lua

41 lines
861 B
Lua
Raw Normal View History

-- 还原 HTTP 请求头
2019-07-24 12:10:07 +00:00
local hasRawRefer = false
2019-04-29 09:34:14 +00:00
2019-07-24 12:10:07 +00:00
local hdrs = ngx.req.get_headers()
local refer = hdrs['referer']
local query = refer:sub(refer:find('?', 10, true) + 1)
local param = ngx.decode_args(query)
2019-04-29 09:34:14 +00:00
2019-07-24 12:10:07 +00:00
for k, v in pairs(param) do
if k:sub(1, 2) == '--' then
k = k:sub(3)
2019-04-29 09:34:14 +00:00
2019-07-24 13:04:22 +00:00
if k == 'ver' then
2019-07-24 12:10:07 +00:00
ngx.var._ver = v
elseif k == 'type' then
ngx.var._type = v
elseif k == 'mode' then
ngx.var._mode = v
elseif k == 'aceh' then
ngx.ctx._acehOld = true
elseif k == 'level' then
ngx.var._level = v
ngx.ctx._level = tonumber(v)
end
else
ngx.req.set_header(k, v)
2019-07-24 12:10:07 +00:00
if k == 'referer' then
hasRawRefer = true
ngx.var._ref = v
end
2019-04-29 09:34:14 +00:00
end
end
2019-07-24 12:10:07 +00:00
if not hasRawRefer then
ngx.req.clear_header('referer')
end
2019-07-24 13:04:22 +00:00
-- 删除 URL 的 '/http/' 前缀
ngx.var._url = ngx.var.request_uri:sub(7)