File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
lib/elasticsearch/transport
spec/elasticsearch/transport Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -194,17 +194,16 @@ def __parse_host(host)
194194 host_parts = case host
195195 when String
196196 if host =~ /^[a-z]+\: \/ \/ /
197- uri = URI . parse ( host )
198-
199- # Handle when port is not specified
200- port = uri . port unless uri . port == uri . default_port
197+ # Construct a new `URI::Generic` directly from the array returned by URI::split.
198+ # This avoids `URI::HTTP` and `URI::HTTPS`, which supply default ports.
199+ uri = URI ::Generic . new ( *URI . split ( host ) )
201200
202201 { :scheme => uri . scheme ,
203202 :user => uri . user ,
204203 :password => uri . password ,
205204 :host => uri . host ,
206205 :path => uri . path ,
207- :port => port }
206+ :port => uri . port }
208207 else
209208 host , port = host . split ( ':' )
210209 { :host => host ,
Original file line number Diff line number Diff line change 314314 end
315315 end
316316
317+ context 'when there is one host with a protocol and the default http port explicitly provided' do
318+ let ( :host ) do
319+ [ 'http://myhost:80' ]
320+ end
321+
322+ it 'respects the explicit port' do
323+ expect ( hosts [ 0 ] [ :port ] ) . to be ( 80 )
324+ end
325+ end
326+
327+ context 'when there is one host with a protocol and the default https port explicitly provided' do
328+ let ( :host ) do
329+ [ 'https://myhost:443' ]
330+ end
331+
332+ it 'respects the explicit port' do
333+ expect ( hosts [ 0 ] [ :port ] ) . to be ( 443 )
334+ end
335+ end
336+
317337 context 'when there is one host with a scheme, protocol and no port' do
318338
319339 let ( :host ) do
You can’t perform that action at this time.
0 commit comments