Skip to content

Commit cac8973

Browse files
committed
Improvements to scheme list and error messages.
1 parent 7c4ed31 commit cac8973

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Diff for: lib/async/http/endpoint.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ 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
21+
SCHEMES = {
22+
'http' => URI::HTTP,
23+
'https' => URI::HTTPS,
24+
'ws' => URI::WS,
25+
'wss' => URI::WSS,
26+
}
2427

2528
def self.parse(string, endpoint = nil, **options)
2629
url = URI.parse(string).normalize
@@ -36,7 +39,7 @@ def self.parse(string, endpoint = nil, **options)
3639
def self.for(scheme, hostname, path = "/", **options)
3740
# TODO: Consider using URI.for once it becomes available:
3841
uri_klass = SCHEMES.fetch(scheme.downcase) do
39-
raise ArgumentError, "Unsupported scheme: #{scheme}"
42+
raise ArgumentError, "Unsupported scheme: #{scheme.inspect}"
4043
end
4144

4245
self.new(

Diff for: test/async/http/endpoint.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@
8686
it "should raise an argument error" do
8787
expect do
8888
Async::HTTP::Endpoint.for("foo", "localhost")
89-
end.to raise_exception(ArgumentError, message: be =~ /scheme/)
89+
end.to raise_exception(ArgumentError, message: be =~ /Unsupported scheme: "foo"/)
9090

9191
expect do
9292
Async::HTTP::Endpoint.for(:http, "localhost", "/foo")
93-
end.to raise_exception(ArgumentError, message: be =~ /scheme/)
93+
end.to raise_exception(ArgumentError, message: be =~ /Unsupported scheme: :http/)
9494
end
9595
end
9696
end

0 commit comments

Comments
 (0)