Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions elasticsearch-transport/lib/elasticsearch/transport/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,16 @@ def __parse_host(host)
host_parts = case host
when String
if host =~ /^[a-z]+\:\/\//
uri = URI.parse(host)

# Handle when port is not specified
port = uri.port unless uri.port == uri.default_port
# Construct a new `URI::Generic` directly from the array returned by URI::split.
# This avoids `URI::HTTP` and `URI::HTTPS`, which supply default ports.
uri = URI::Generic.new(*URI.split(host))

{ :scheme => uri.scheme,
:user => uri.user,
:password => uri.password,
:host => uri.host,
:path => uri.path,
:port => port }
:port => uri.port }
else
host, port = host.split(':')
{ :host => host,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@
end
end

context 'when there is one host with a protocol and the default http port explicitly provided' do
let(:host) do
['http://myhost:80']
end

it 'respects the explicit port' do
expect(hosts[0][:port]).to be(80)
end
end

context 'when there is one host with a protocol and the default https port explicitly provided' do
let(:host) do
['https://myhost:443']
end

it 'respects the explicit port' do
expect(hosts[0][:port]).to be(443)
end
end

context 'when there is one host with a scheme, protocol and no port' do

let(:host) do
Expand Down