【发布时间】:2021-01-01 06:04:09
【问题描述】:
我是 Lua 和 Nginx 的新手。我有一个 Lua 文件,它对命中 NGINX 的任何请求进行身份验证。
local ffi = require("ffi")
local cjson = require("cjson")
local iam = ffi.load("/gateway/auth/main/libiam.so")
ffi.cdef([[
typedef long long GoInt64;
typedef GoInt64 GoInt;
typedef struct { const char *p; GoInt n; } GoString;
extern GoInt VerifyToken(GoString p0);
extern GoInt64 VerifyApiKey(GoString p0);
]]);
local accessToken = ""
local apiKey = ""
local result = 0
local typeString = ffi.typeof("GoString")
local unauthorizedJson={}
if ngx.var.http_Authorization and string.len(ngx.var.http_Authorization) > 0 then
if ngx.var.http_Authorization:sub(1, #"Bearer") == "Bearer" then
ngx.log(ngx.STDERR, 'Verifying bearer token.')
accessToken = string.sub(ngx.var.http_Authorization,8)
local accessTokenString= typeString(accessToken, string.len(accessToken))
result = iam.VerifyToken(accessTokenString)
else
apiKey = ngx.var.http_Authorization
local apiKeyString= typeString(apiKey, string.len(apiKey))
result = iam.VerifyApiKey(apiKeyString)
end
if tonumber(result)~=0 then
-- we are ok here and proceed to route to upstream
if string.len(apiKey) > 0 then
ngx.req.set_header("abc", result)
end
else
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
else
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
我间歇性地看到以下错误
Lua entry thread aborted: runtime error: table overflow
在这一行
ffi.cdef([[
我正在使用 openresty。谁能告诉我这里可能是什么问题?
【问题讨论】: