From 9710d254ff14b65bfe6a19f80228c33b7a6c1618 Mon Sep 17 00:00:00 2001 From: moicen Date: Sun, 7 May 2023 02:49:52 +0800 Subject: [PATCH] parse complete url for upt calculation --- opm_install_require.sh | 5 ++++- scripts/lib/upt.lua | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/opm_install_require.sh b/opm_install_require.sh index 1690a57..046ac40 100644 --- a/opm_install_require.sh +++ b/opm_install_require.sh @@ -12,4 +12,7 @@ opm get SkyLothar/lua-resty-jwt opm get ledgetech/lua-resty-http # UUID -opm get thibaultcha/lua-resty-jit-uuid \ No newline at end of file +opm get thibaultcha/lua-resty-jit-uuid + +#URI +opm get liyo/neturl \ No newline at end of file diff --git a/scripts/lib/upt.lua b/scripts/lib/upt.lua index 1435856..827a06f 100644 --- a/scripts/lib/upt.lua +++ b/scripts/lib/upt.lua @@ -2,15 +2,19 @@ --package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua'; package.path = package.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)