Skip to content

Commit 423d6dd

Browse files
committed
More tests.
1 parent f4d251c commit 423d6dd

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

lib/async/http/protocol/http.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def protocol_for(stream)
5656
def client(peer, **options)
5757
options = options[@http1] || {}
5858

59-
@http1.client(peer, **options)
59+
return @http1.client(peer, **options)
6060
end
6161

6262
# Create a server for an inbound connection. Able to detect HTTP1 and HTTP2.
6363
#
6464
# @parameter peer [IO] The peer to communicate with.
6565
# @parameter options [Hash] Options to pass to the protocol, keyed by protocol class.
6666
def server(peer, **options)
67-
stream = ::IO::Stream(peer)
67+
stream = IO::Stream(peer)
6868
protocol = protocol_for(stream)
6969
options = options[protocol] || {}
7070

test/async/http/protocol/http.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
with ".default" do
1414
it "has a default instance" do
15-
expect(subject.default).to be_a Async::HTTP::Protocol::HTTP
15+
expect(protocol).to be_a Async::HTTP::Protocol::HTTP
1616
end
1717
end
1818

test/async/http/protocol/https.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2025, by Samuel Williams.
5+
6+
require "async/http/protocol/https"
7+
require "async/http/a_protocol"
8+
9+
describe Async::HTTP::Protocol::HTTPS do
10+
let(:protocol) {subject.default}
11+
12+
with ".default" do
13+
it "has a default instance" do
14+
expect(protocol).to be_a Async::HTTP::Protocol::HTTPS
15+
end
16+
17+
it "supports http/1.0" do
18+
expect(protocol.names).to be(:include?, "http/1.0")
19+
end
20+
21+
it "supports http/1.1" do
22+
expect(protocol.names).to be(:include?, "http/1.1")
23+
end
24+
25+
it "supports h2" do
26+
expect(protocol.names).to be(:include?, "h2")
27+
end
28+
end
29+
30+
with "#protocol_for" do
31+
let(:buffer) {StringIO.new}
32+
33+
it "can detect http/1.0" do
34+
stream = IO::Stream(buffer)
35+
expect(stream).to receive(:alpn_protocol).and_return("http/1.0")
36+
37+
expect(protocol.protocol_for(stream)).to be == Async::HTTP::Protocol::HTTP10
38+
end
39+
40+
it "it can detect http/1.1" do
41+
stream = IO::Stream(buffer)
42+
expect(stream).to receive(:alpn_protocol).and_return("http/1.1")
43+
44+
expect(protocol.protocol_for(stream)).to be == Async::HTTP::Protocol::HTTP11
45+
end
46+
47+
it "it can detect http/2" do
48+
stream = IO::Stream(buffer)
49+
expect(stream).to receive(:alpn_protocol).and_return("h2")
50+
51+
expect(protocol.protocol_for(stream)).to be == Async::HTTP::Protocol::HTTP2
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)