lib/async/http/endpoint.rb in async-http-0.49.1 vs lib/async/http/endpoint.rb in async-http-0.50.0
- old
+ new
@@ -35,10 +35,21 @@
url = URI.parse(string).normalize
return self.new(url, endpoint, **options)
end
+ # Construct an endpoint with a specified scheme, hostname, and options.
+ def self.for(scheme, hostname, **options)
+ # TODO: Consider using URI.for once it becomes available:
+ uri_klass = URI.scheme_list[scheme.upcase] || URI::HTTP
+
+ self.new(
+ uri_klass.new(scheme, nil, hostname, nil, nil, nil, nil, nil, 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 ssl_context [OpenSSL::SSL::SSLContext] the context to use for TLS.
# @option alpn_protocols [Array<String>] the alpn protocols to negotiate.
@@ -79,10 +90,10 @@
def address
endpoint.address
end
def secure?
- ['https', 'wss'].include?(@url.scheme)
+ ['https', 'wss'].include?(self.scheme)
end
def protocol
@options.fetch(:protocol) do
if secure?
\ No newline at end of file