[7.x] Support IPv6 braces in Connection.host
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
This commit is contained in:
committed by
GitHub
parent
3d14e4ff27
commit
876bf90943
@@ -137,7 +137,10 @@ class Connection(object):
|
||||
self.scheme = scheme
|
||||
self.hostname = host
|
||||
self.port = port
|
||||
self.host = "%s://%s" % (scheme, host)
|
||||
if ":" in host: # IPv6
|
||||
self.host = "%s://[%s]" % (scheme, host)
|
||||
else:
|
||||
self.host = "%s://%s" % (scheme, host)
|
||||
if self.port is not None:
|
||||
self.host += ":%s" % self.port
|
||||
if url_prefix:
|
||||
|
||||
@@ -150,6 +150,17 @@ class TestBaseConnection(TestCase):
|
||||
|
||||
self.assertEqual([str(w.message) for w in warn], ["warning", "folded"])
|
||||
|
||||
def test_ipv6_host_and_port(self):
|
||||
for kwargs, expected_host in [
|
||||
({"host": "::1"}, "http://[::1]:9200"),
|
||||
({"host": "::1", "port": 443}, "http://[::1]:443"),
|
||||
({"host": "::1", "use_ssl": True}, "https://[::1]:9200"),
|
||||
({"host": "127.0.0.1", "port": 1234}, "http://127.0.0.1:1234"),
|
||||
({"host": "localhost", "use_ssl": True}, "https://localhost:9200"),
|
||||
]:
|
||||
conn = Connection(**kwargs)
|
||||
assert conn.host == expected_host
|
||||
|
||||
|
||||
class TestUrllib3Connection(TestCase):
|
||||
def _get_mock_connection(self, connection_params={}, response_body=b"{}"):
|
||||
|
||||
Reference in New Issue
Block a user