Skip to content

Commit 9e83ffd

Browse files
estolfopicandocodigo
authored andcommitted
[CLIENT] Use 443 for default cloud port, 9200 as the default port for http
Adds more test cases Partly backported from 80f26fd
1 parent f095dbc commit 9e83ffd

File tree

3 files changed

+325
-136
lines changed

3 files changed

+325
-136
lines changed

elasticsearch-transport/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Please see below for an exception to this when connecting using an Elastic Cloud
136136

137137
If you are using [Elastic Cloud](https://www.elastic.co/cloud), you can provide your cloud id to the client.
138138
You must supply your username and password separately, and optionally a port. If no port is supplied,
139-
port 9243 will be used.
139+
port 443 will be used.
140140

141141
Note: Do not enable sniffing when using Elastic Cloud. The nodes are behind a load balancer so
142142
Elastic Cloud will take care of everything for you.

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

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ class Client
4949
DEFAULT_HOST = 'localhost:9200'.freeze
5050

5151
# The default port to use if connecting using a Cloud ID.
52+
# Updated from 9243 to 443 in client version 7.10.1
5253
#
5354
# @since 7.2.0
54-
DEFAULT_CLOUD_PORT = 9243
55+
DEFAULT_CLOUD_PORT = 443
56+
57+
# The default port to use if not otherwise specified.
58+
#
59+
# @since 7.2.0
60+
DEFAULT_PORT = 9200
5561

5662
# Returns the transport object.
5763
#
@@ -243,36 +249,38 @@ def __extract_hosts(hosts_config)
243249

244250
def __parse_host(host)
245251
host_parts = case host
246-
when String
247-
if host =~ /^[a-z]+\:\/\//
248-
# Construct a new `URI::Generic` directly from the array returned by URI::split.
249-
# This avoids `URI::HTTP` and `URI::HTTPS`, which supply default ports.
250-
uri = URI::Generic.new(*URI.split(host))
251-
252-
{ :scheme => uri.scheme,
253-
:user => uri.user,
254-
:password => uri.password,
255-
:host => uri.host,
256-
:path => uri.path,
257-
:port => uri.port }
258-
else
259-
host, port = host.split(':')
260-
{ :host => host,
261-
:port => port }
262-
end
263-
when URI
264-
{ :scheme => host.scheme,
265-
:user => host.user,
266-
:password => host.password,
267-
:host => host.host,
268-
:path => host.path,
269-
:port => host.port }
270-
when Hash
271-
host
272-
else
273-
raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
274-
end
275-
252+
when String
253+
if host =~ /^[a-z]+\:\/\//
254+
# Construct a new `URI::Generic` directly from the array returned by URI::split.
255+
# This avoids `URI::HTTP` and `URI::HTTPS`, which supply default ports.
256+
uri = URI::Generic.new(*URI.split(host))
257+
default_port = uri.scheme == 'https' ? 443 : DEFAULT_PORT
258+
{
259+
scheme: uri.scheme,
260+
user: uri.user,
261+
password: uri.password,
262+
host: uri.host,
263+
path: uri.path,
264+
port: uri.port || default_port
265+
}
266+
else
267+
host, port = host.split(':')
268+
{ host: host, port: port }
269+
end
270+
when URI
271+
{
272+
scheme: host.scheme,
273+
user: host.user,
274+
password: host.password,
275+
host: host.host,
276+
path: host.path,
277+
port: host.port
278+
}
279+
when Hash
280+
host
281+
else
282+
raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
283+
end
276284
if @api_key
277285
# Remove Basic Auth if using API KEY
278286
host_parts.delete(:user)

0 commit comments

Comments
 (0)