parse complete url for upt calculation

This commit is contained in:
moicen
2023-05-07 02:49:52 +08:00
parent ee17b2f175
commit 9710d254ff
2 changed files with 12 additions and 5 deletions
+3
View File
@@ -13,3 +13,6 @@ opm get ledgetech/lua-resty-http
# UUID
opm get thibaultcha/lua-resty-jit-uuid
#URI
opm get liyo/neturl
+8 -4
View File
@@ -2,15 +2,19 @@
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local url_parser = require "net.url"
local _M = {}
function host(s)
return (s.."/"):match("://(.-)/")
end
function _M.upt(uri)
local hostname = host(uri)
ngx.log(ngx.INFO, 'hostname...', hostname)
function _M.upt(url)
local uri = url_parser.parse(url)
local hostname = uri.host
local pathname = uri.path
ngx.log(ngx.INFO, 'hostname...' .. hostname .. ' path...' .. pathname)
local secret;
if string.find(hostname, "moicen.com") then
secret = ngx.var.upt_moicen_secret
@@ -23,7 +27,7 @@ function _M.upt(uri)
ngx.log(ngx.INFO, 'secret...' .. secret)
local duration = ngx.var.upt_duration
local etime = os.time() + duration
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. uri)
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. pathname)
ngx.log(ngx.INFO, 'sign...' .. sign .. ' etime..' .. etime)
local upt = string.sub(sign, 13, 13 + 7) .. etime
ngx.log(ngx.INFO, 'upt...' .. upt)