Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions common/clickhouse_logica.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
settings or via environment variables.

Environment variables:
LOGICA_CLICKHOUSE_HOST (default: 127.0.0.1)
LOGICA_CLICKHOUSE_HOST (default: 127.0.0.1; may include http:// or https://)
LOGICA_CLICKHOUSE_PORT (default: 8123)
LOGICA_CLICKHOUSE_USER (default: default)
LOGICA_CLICKHOUSE_PASSWORD (default: "")
Expand Down Expand Up @@ -186,7 +186,18 @@ def HttpRequest(sql, *, settings):
if v is None:
continue
params[str(k)] = str(v)
url = f"http://{settings['host']}:{settings['port']}/?" + urllib.parse.urlencode(params)
host = str(settings['host'])
port = int(settings['port'])
scheme = 'http'
if '://' in host:
parsed = urllib.parse.urlparse(host)
scheme = parsed.scheme or scheme
host = parsed.hostname or host
port = int(parsed.port or (443 if scheme == 'https' else port))

base_url = f'{scheme}://{host}:{port}'

url = base_url.rstrip('/') + '/?' + urllib.parse.urlencode(params)
req = urllib.request.Request(
url,
data=(sql + "\n").encode('utf-8'),
Expand Down