[7.x] Support IPv6 braces in Connection.host
Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
co-authored by
Seth Michael Larson
parent
3d14e4ff27
commit
876bf90943
@@ -137,6 +137,9 @@ class Connection(object):
|
|||||||
self.scheme = scheme
|
self.scheme = scheme
|
||||||
self.hostname = host
|
self.hostname = host
|
||||||
self.port = port
|
self.port = port
|
||||||
|
if ":" in host: # IPv6
|
||||||
|
self.host = "%s://[%s]" % (scheme, host)
|
||||||
|
else:
|
||||||
self.host = "%s://%s" % (scheme, host)
|
self.host = "%s://%s" % (scheme, host)
|
||||||
if self.port is not None:
|
if self.port is not None:
|
||||||
self.host += ":%s" % self.port
|
self.host += ":%s" % self.port
|
||||||
|
|||||||
@@ -150,6 +150,17 @@ class TestBaseConnection(TestCase):
|
|||||||
|
|
||||||
self.assertEqual([str(w.message) for w in warn], ["warning", "folded"])
|
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):
|
class TestUrllib3Connection(TestCase):
|
||||||
def _get_mock_connection(self, connection_params={}, response_body=b"{}"):
|
def _get_mock_connection(self, connection_params={}, response_body=b"{}"):
|
||||||
|
|||||||
Reference in New Issue
Block a user