🌐 AI搜索 & 代理 主页
Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 84d73ca

Browse files
committed
ensure CONSUL_HTTP_ADDR starts with a scheme, either http or https if CONSUL_HTTP_SSL is set
Signed-off-by: Steven Armstrong <steven.armstrong@id.ethz.ch>
1 parent 905b598 commit 84d73ca

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

consul/base.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,26 @@ def from_env(cls, consistency='default', dc=None):
352352
kwargs = {
353353
'consistency': consistency,
354354
'dc': dc,
355-
'addr': oe.get('CONSUL_HTTP_ADDR', None),
356355
'token': oe.get('CONSUL_HTTP_TOKEN', None),
357356
}
357+
358+
addr = oe.get('CONSUL_HTTP_ADDR', None)
359+
if addr:
360+
if not addr.startswith('http'):
361+
# Ensure addr starts with a scheme.
362+
ssl = oe.get('CONSUL_HTTP_SSL', False)
363+
if ssl == 'false':
364+
ssl = False
365+
elif ssl == 'true':
366+
ssl = True
367+
368+
if ssl:
369+
scheme = 'https'
370+
else:
371+
scheme = 'http'
372+
addr = '%s://%s' % (scheme, addr)
373+
kwargs['addr'] = addr
374+
358375
verify = oe.get('CONSUL_CACERT',
359376
oe.get('CONSUL_HTTP_SSL_VERIFY', None))
360377
if verify:

0 commit comments

Comments
 (0)