File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
lib/elasticsearch/transport
spec/elasticsearch/transport Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ def __parse_host(host)
197197 uri = URI . parse ( host )
198198
199199 # Handle when port is not specified
200- if host =~ /^ #{ uri . scheme } : \/ \/ #{ uri . host } $/
200+ if uri . port == uri . default_port
201201 port = nil
202202 else
203203 port = uri . port
Original file line number Diff line number Diff line change 301301 end
302302 end
303303
304+ context 'when there is one host with a protocol and no port' do
305+
306+ let ( :host ) do
307+ [ 'http://myhost' ]
308+ end
309+
310+ it 'extracts the host' do
311+ expect ( hosts [ 0 ] [ :host ] ) . to eq ( 'myhost' )
312+ expect ( hosts [ 0 ] [ :protocol ] ) . to eq ( 'http' )
313+ expect ( hosts [ 0 ] [ :port ] ) . to be ( 9200 )
314+ end
315+ end
316+
317+ context 'when there is one host with a scheme, protocol and no port' do
318+
319+ let ( :host ) do
320+ [ 'https://myhost' ]
321+ end
322+
323+ it 'extracts the host' do
324+ expect ( hosts [ 0 ] [ :host ] ) . to eq ( 'myhost' )
325+ expect ( hosts [ 0 ] [ :protocol ] ) . to eq ( 'https' )
326+ expect ( hosts [ 0 ] [ :port ] ) . to be ( 9200 )
327+ end
328+ end
329+
330+ context 'when there is one host with a scheme, protocol and no port' do
331+
332+ let ( :host ) do
333+ [ 'http://myhost/foo/bar' ]
334+ end
335+
336+ it 'extracts the host' do
337+ expect ( hosts [ 0 ] [ :host ] ) . to eq ( 'myhost' )
338+ expect ( hosts [ 0 ] [ :protocol ] ) . to eq ( 'http' )
339+ expect ( hosts [ 0 ] [ :port ] ) . to be ( 9200 )
340+ expect ( hosts [ 0 ] [ :path ] ) . to eq ( "/foo/bar" )
341+ end
342+ end
343+
304344 context 'when there is more than one host' do
305345
306346 let ( :host ) do
939979 end
940980 end
941981 end
942- end
982+ end
You can’t perform that action at this time.
0 commit comments