lib/async/http/endpoint.rb in async-http-0.67.1 vs lib/async/http/endpoint.rb in async-http-0.68.0
- old
+ new
@@ -1,10 +1,11 @@
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2021-2022, by Adam Daniels.
+# Copyright, 2024, by Thomas Morgan.
require 'io/endpoint'
require 'io/endpoint/host_endpoint'
require 'io/endpoint/ssl_endpoint'
@@ -28,9 +29,19 @@
self.new(
uri_klass.new(scheme, nil, hostname, nil, nil, path, nil, nil, nil).normalize,
**options
)
+ end
+
+ # Coerce the given object into an endpoint.
+ # @parameter url [String | Endpoint] The URL or endpoint to convert.
+ def self.[](url)
+ if url.is_a?(Endpoint)
+ return url
+ else
+ Endpoint.parse(url.to_str)
+ end
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.