Skip to content

Commit d21ded2

Browse files
Expose HTTP protocol names. (#228)
1 parent aba0d64 commit d21ded2

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/async/http/protocol/http.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def initialize(http1: HTTP1, http2: HTTP2)
2626
@http2 = http2
2727
end
2828

29+
# The names of all supported protocols.
30+
# @returns [Array(String)] The supported protocol names.
31+
def names
32+
(@http2.names + @http1.names).uniq
33+
end
34+
2935
# Determine if the inbound connection is HTTP/1 or HTTP/2.
3036
#
3137
# @parameter stream [IO::Stream] The stream to detect the protocol for.

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Exposed all supported protocol names from the plaintext HTTP protocol negotiator.
6+
37
## v0.96.0
48

59
- Made `metrics` and `traces` optional runtime dependencies. Applications that use the providers should depend on the corresponding gem and require the provider explicitly.

test/async/http/protocol/http.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
it "has a default instance" do
1515
expect(protocol).to be_a Async::HTTP::Protocol::HTTP
1616
end
17+
18+
it "exposes the supported protocol names" do
19+
expect(subject.names).to be == ["h2", "http/1.1", "http/1.0"]
20+
end
21+
end
22+
23+
with "configured protocols" do
24+
let(:protocol) {subject.new(http1: Async::HTTP::Protocol::HTTP11, http2: Async::HTTP::Protocol::HTTP2)}
25+
26+
it "exposes their supported protocol names" do
27+
expect(protocol.names).to be == ["h2", "http/1.1"]
28+
end
1729
end
1830

1931
with "#protocol_for" do

0 commit comments

Comments
 (0)