parse complete url for upt calculation
This commit is contained in:
@@ -12,4 +12,7 @@ opm get SkyLothar/lua-resty-jwt
|
||||
opm get ledgetech/lua-resty-http
|
||||
|
||||
# UUID
|
||||
opm get thibaultcha/lua-resty-jit-uuid
|
||||
opm get thibaultcha/lua-resty-jit-uuid
|
||||
|
||||
#URI
|
||||
opm get liyo/neturl
|
||||
+8
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user