@@ -18,16 +18,26 @@ module Async
18
18
module HTTP
19
19
# Represents a way to connect to a remote HTTP server.
20
20
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
+
21
25
def self . parse ( string , endpoint = nil , **options )
22
26
url = URI . parse ( string ) . normalize
23
27
24
28
return self . new ( url , endpoint , **options )
25
29
end
26
30
27
31
# 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}.
28
36
def self . for ( scheme , hostname , path = "/" , **options )
29
37
# 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
31
41
32
42
self . new (
33
43
uri_klass . new ( scheme , nil , hostname , nil , nil , path , nil , nil , nil ) . normalize ,
0 commit comments