@@ -146,16 +146,17 @@ function _M.new(opts)
146146 end
147147
148148 for _ , host in ipairs (http_hosts ) do
149- local m , err = re_match (host , [[ \/\/([\d.\w]+):(\d+)]] , " jo" )
149+ local m , err = re_match (host , [[ ([^\/]+)\: \/\/([\d.\w]+):(\d+)]] , " jo" )
150150 if not m then
151151 return nil , " invalid http host: " .. err
152152 end
153153
154154 tab_insert (endpoints , {
155155 full_prefix = host .. utils .normalize (api_prefix ),
156156 http_host = host ,
157- host = m [1 ] or " 127.0.0.1" ,
158- port = m [2 ] or " 2379" ,
157+ scheme = m [1 ],
158+ host = m [2 ] or " 127.0.0.1" ,
159+ port = m [3 ] or " 2379" ,
159160 api_prefix = api_prefix ,
160161 })
161162 end
@@ -450,7 +451,7 @@ local function txn(self, opts_arg, compare, success, failure)
450451end
451452
452453
453- local function request_chunk (self , method , host , port , path , opts , timeout )
454+ local function request_chunk (self , method , scheme , host , port , path , opts , timeout )
454455 local body , err , _
455456 if opts and opts .body and tab_nkeys (opts .body ) > 0 then
456457 body , err = encode_json (opts .body )
@@ -493,6 +494,18 @@ local function request_chunk(self, method, host, port, path, opts, timeout)
493494 return nil , err
494495 end
495496
497+ if scheme == " https" then
498+ local verify = true
499+ if self .ssl_verify == false then
500+ verify = false
501+ end
502+
503+ ok , err = http_cli :ssl_handshake (nil , host , verify )
504+ if not ok then
505+ return nil , err
506+ end
507+ end
508+
496509 local res
497510 res , err = http_cli :request ({
498511 method = method ,
@@ -639,6 +652,7 @@ local function watch(self, key, attr)
639652 local endpoint = choose_endpoint (self )
640653
641654 local callback_fun , err , http_cli = request_chunk (self , ' POST' ,
655+ endpoint .scheme ,
642656 endpoint .host ,
643657 endpoint .port ,
644658 endpoint .api_prefix .. ' /watch' , opts ,
0 commit comments