Merge pull request #3674 from moonming/cjson-safe
used cjson.safe instead of pcall.
This commit is contained in:
commit
42d3f68992
4 changed files with 18 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
local ngx_balancer = require("ngx.balancer")
|
||||
local json = require("cjson")
|
||||
local cjson = require("cjson.safe")
|
||||
local util = require("util")
|
||||
local dns_util = require("util.dns")
|
||||
local configuration = require("configuration")
|
||||
|
@ -114,9 +114,9 @@ local function sync_backends()
|
|||
return
|
||||
end
|
||||
|
||||
local ok, new_backends = pcall(json.decode, backends_data)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "could not parse backends data: " .. tostring(new_backends))
|
||||
local new_backends, err = cjson.decode(backends_data)
|
||||
if not new_backends then
|
||||
ngx.log(ngx.ERR, "could not parse backends data: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local json = require("cjson")
|
||||
local cjson = require("cjson.safe")
|
||||
|
||||
-- this is the Lua representation of Configuration struct in internal/ingress/types.go
|
||||
local configuration_data = ngx.shared.configuration_data
|
||||
|
@ -49,9 +49,9 @@ local function handle_servers()
|
|||
|
||||
local raw_servers = fetch_request_body()
|
||||
|
||||
local ok, servers = pcall(json.decode, raw_servers)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "could not parse servers: " .. tostring(servers))
|
||||
local servers, err = cjson.decode(raw_servers)
|
||||
if not servers then
|
||||
ngx.log(ngx.ERR, "could not parse servers: ", err)
|
||||
ngx.status = ngx.HTTP_BAD_REQUEST
|
||||
return
|
||||
end
|
||||
|
@ -59,7 +59,8 @@ local function handle_servers()
|
|||
local err_buf = {}
|
||||
for _, server in ipairs(servers) do
|
||||
if server.hostname and server.sslCert.pemCertKey then
|
||||
local success, err = certificate_data:safe_set(server.hostname, server.sslCert.pemCertKey)
|
||||
local success
|
||||
success, err = certificate_data:safe_set(server.hostname, server.sslCert.pemCertKey)
|
||||
if not success then
|
||||
if err == "no memory" then
|
||||
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local socket = ngx.socket.tcp
|
||||
local cjson = require('cjson')
|
||||
local cjson = require("cjson.safe")
|
||||
local assert = assert
|
||||
|
||||
local metrics_batch = {}
|
||||
|
@ -49,9 +49,9 @@ local function flush(premature)
|
|||
local current_metrics_batch = metrics_batch
|
||||
metrics_batch = {}
|
||||
|
||||
local ok, payload = pcall(cjson.encode, current_metrics_batch)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "error while encoding metrics: " .. tostring(payload))
|
||||
local payload, err = cjson.encode(current_metrics_batch)
|
||||
if not payload then
|
||||
ngx.log(ngx.ERR, "error while encoding metrics: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local ngx_balancer = require("ngx.balancer")
|
||||
local json = require("cjson")
|
||||
local cjson = require("cjson.safe")
|
||||
local util = require("util")
|
||||
local dns_util = require("util.dns")
|
||||
local configuration = require("tcp_udp_configuration")
|
||||
|
@ -99,9 +99,9 @@ local function sync_backends()
|
|||
return
|
||||
end
|
||||
|
||||
local ok, new_backends = pcall(json.decode, backends_data)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "could not parse backends data: " .. tostring(new_backends))
|
||||
local new_backends, err = cjson.decode(backends_data)
|
||||
if not new_backends then
|
||||
ngx.log(ngx.ERR, "could not parse backends data: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue