Skip to content

Commit ad3ae56

Browse files
committed
Add test for HTTP#protocol_for.
1 parent 5dca8a8 commit ad3ae56

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/async/http/protocol/http.rb

+25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88
require "async/http/a_protocol"
99

1010
describe Async::HTTP::Protocol::HTTP do
11+
with "#protocol_for" do
12+
let(:protocol) {subject::DEFAULT}
13+
let(:buffer) {StringIO.new}
14+
15+
it "it can detect http/1.1" do
16+
buffer.write("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n")
17+
buffer.rewind
18+
19+
stream = IO::Stream(buffer)
20+
21+
expect(protocol.protocol_for(stream)).to be == Async::HTTP::Protocol::HTTP1
22+
end
23+
24+
it "it can detect http/2" do
25+
# This special preface is used to indicate that the client would like to use HTTP/2.
26+
# https://www.rfc-editor.org/rfc/rfc7540.html#section-3.5
27+
buffer.write("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
28+
buffer.rewind
29+
30+
stream = IO::Stream(buffer)
31+
32+
expect(protocol.protocol_for(stream)).to be == Async::HTTP::Protocol::HTTP2
33+
end
34+
end
35+
1136
with "server" do
1237
include Sus::Fixtures::Async::HTTP::ServerContext
1338
let(:protocol) {subject}

0 commit comments

Comments
 (0)