Skip to content

Commit ca4eb72

Browse files
seko0716estolfo
authored andcommitted
handle IPv6 host (#614)
* add ipv6 support * add ipv6 support * add ipv6 support add test
1 parent 51ca559 commit ca4eb72

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

elasticsearch-transport/lib/elasticsearch/transport/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ def __parse_host(host)
201201
:host => uri.host,
202202
:path => uri.path,
203203
:port => uri.port }
204+
elsif host =~ /^\[[a-z0-9:]+\]:[0-9]+/
205+
host, sep, port = host.rpartition(':')
206+
{:host => host,
207+
:port => port}
204208
else
205209
host, port = host.split(':')
206210
{ :host => host,

elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@
126126
expect(hosts[0][:port]).to be(9200)
127127
end
128128

129+
context 'when ipv6 is specified' do
130+
131+
let(:host) do
132+
'[fd95:ff55:7fb8:f1e5:f816:3eff:feed:ce5b]:9200'
133+
end
134+
135+
it 'extracts the host' do
136+
expect(hosts[0][:host]).to eq('[fd95:ff55:7fb8:f1e5:f816:3eff:feed:ce5b]')
137+
expect(hosts[0][:scheme]).to eq('http')
138+
expect(hosts[0][:port]).to be(9200)
139+
end
140+
end
141+
129142
context 'when a path is specified' do
130143

131144
let(:host) do

0 commit comments

Comments
 (0)