lib/async/http/endpoint.rb in async-http-0.46.0 vs lib/async/http/endpoint.rb in async-http-0.46.1
- old
+ new
@@ -34,12 +34,12 @@
return self.new(url, nil, **options)
end
# @option scheme [String] the scheme to use, overrides the URL scheme.
+ # @option hostname [String] the hostname to connect to (or bind to), overrides the URL hostname (used for SNI).
# @option port [Integer] the port to bind to, overrides the URL port.
- # @option hostname [String] the hostname to use, overrides the URL hostname.
# @option ssl_context [OpenSSL::SSL::SSLContext] the context to use for TLS.
# @option alpn_protocols [Array<String>] the alpn protocols to negotiate.
def initialize(url, endpoint = nil, **options)
super(**options)
@@ -58,11 +58,11 @@
return url
end
def to_s
- "\#<#{self.class} #{self.to_url}>"
+ "\#<#{self.class} #{self.to_url} #{@options}>"
end
def inspect
"\#<#{self.class} #{self.to_url} #{@options.inspect}>"
end
@@ -97,23 +97,24 @@
def port
@options[:port] || @url.port || default_port
end
+ # The hostname is the server we are connecting to:
def hostname
@options[:hostname] || @url.hostname
end
def scheme
@options[:scheme] || @url.scheme
end
def authority
if default_port?
- hostname
+ @url.hostname
else
- "#{hostname}:#{port}"
+ "#{@url.hostname}:#{port}"
end
end
# Return the path and query components of the given URL.
def path
@@ -129,11 +130,11 @@
def alpn_protocols
@options.fetch(:alpn_protocols) {self.protocol.names}
end
def localhost?
- self.hostname =~ /^(.*?\.)?localhost\.?$/
+ @url.hostname =~ /^(.*?\.)?localhost\.?$/
end
# We don't try to validate peer certificates when talking to localhost because they would always be self-signed.
def ssl_verify_mode
if self.localhost?
@@ -167,16 +168,16 @@
return options
end
def build_endpoint(endpoint = nil)
- endpoint ||= Async::IO::Endpoint.tcp(hostname, port, tcp_options)
+ endpoint ||= Async::IO::Endpoint.tcp(self.hostname, port, tcp_options)
if secure?
# Wrap it in SSL:
return Async::IO::SSLEndpoint.new(endpoint,
ssl_context: self.ssl_context,
- hostname: self.hostname,
+ hostname: @url.hostname,
timeout: self.timeout,
)
end
return endpoint
\ No newline at end of file