@@ -18,16 +18,26 @@ module Async
1818 module HTTP
1919 # Represents a way to connect to a remote HTTP server.
2020 class Endpoint < ::IO ::Endpoint ::Generic
21+ SCHEMES = [ 'HTTP' , 'HTTPS' , 'WS' , 'WSS' ] . to_h do |scheme |
22+ [ scheme . downcase , URI . scheme_list [ scheme ] ]
23+ end
24+
2125 def self . parse ( string , endpoint = nil , **options )
2226 url = URI . parse ( string ) . normalize
2327
2428 return self . new ( url , endpoint , **options )
2529 end
2630
2731 # Construct an endpoint with a specified scheme, hostname, optional path, and options.
32+ #
33+ # @parameter scheme [String] The scheme to use, e.g. "http" or "https".
34+ # @parameter hostname [String] The hostname to connect to (or bind to).
35+ # @parameter *options [Hash] Additional options, passed to {#initialize}.
2836 def self . for ( scheme , hostname , path = "/" , **options )
2937 # TODO: Consider using URI.for once it becomes available:
30- uri_klass = URI . scheme_list [ scheme . upcase ] || URI ::HTTP
38+ uri_klass = SCHEMES . fetch ( scheme . downcase ) do
39+ raise ArgumentError , "Unsupported scheme: #{ scheme } "
40+ end
3141
3242 self . new (
3343 uri_klass . new ( scheme , nil , hostname , nil , nil , path , nil , nil , nil ) . normalize ,
0 commit comments