1
1
-- https://github.com/ledgetech/lua-resty-http
2
+ local require = require
2
3
local split = require (" ngx.re" ).split
3
4
local typeof = require (" typeof" )
4
5
local cjson = require (" cjson.safe" )
@@ -27,6 +28,7 @@ local decode_base64 = ngx.decode_base64
27
28
local semaphore = require (" ngx.semaphore" )
28
29
local health_check = require (" resty.etcd.health_check" )
29
30
local pl_path = require (" pl.path" )
31
+ local pcall = pcall
30
32
31
33
math.randomseed (now () * 1000 + ngx .worker .pid ())
32
34
@@ -265,6 +267,17 @@ local function serialize_and_encode_base64(serialize_fn, data)
265
267
return encode_base64 (data )
266
268
end
267
269
270
+ local function require_serializer (serializer_name )
271
+ if serializer_name then
272
+ local ok , module = pcall (require , " resty.etcd.serializers." .. serializer_name )
273
+ if ok then
274
+ return module
275
+ end
276
+ end
277
+
278
+ return require (" resty.etcd.serializers.json" )
279
+ end
280
+
268
281
269
282
function _M .new (opts )
270
283
local timeout = opts .timeout
@@ -278,7 +291,7 @@ function _M.new(opts)
278
291
if ssl_verify == nil then
279
292
ssl_verify = true
280
293
end
281
- local serializer = opts .serializer
294
+ local serializer = require_serializer ( opts .serializer )
282
295
local extra_headers = opts .extra_headers
283
296
local sni = opts .sni
284
297
local unix_socket_proxy = opts .unix_socket_proxy
0 commit comments