diff --git a/lib/async/http/protocol/http.rb b/lib/async/http/protocol/http.rb index 97d8f37..a1c5e41 100644 --- a/lib/async/http/protocol/http.rb +++ b/lib/async/http/protocol/http.rb @@ -26,6 +26,12 @@ def initialize(http1: HTTP1, http2: HTTP2) @http2 = http2 end + # The names of all supported protocols. + # @returns [Array(String)] The supported protocol names. + def names + (@http2.names + @http1.names).uniq + end + # Determine if the inbound connection is HTTP/1 or HTTP/2. # # @parameter stream [IO::Stream] The stream to detect the protocol for. diff --git a/releases.md b/releases.md index de2e0ce..cd9b4f4 100644 --- a/releases.md +++ b/releases.md @@ -1,5 +1,9 @@ # Releases +## Unreleased + + - Exposed all supported protocol names from the plaintext HTTP protocol negotiator. + ## v0.96.0 - Made `metrics` and `traces` optional runtime dependencies. Applications that use the providers should depend on the corresponding gem and require the provider explicitly. diff --git a/test/async/http/protocol/http.rb b/test/async/http/protocol/http.rb index 4a151a1..3a9ad9c 100755 --- a/test/async/http/protocol/http.rb +++ b/test/async/http/protocol/http.rb @@ -14,6 +14,18 @@ it "has a default instance" do expect(protocol).to be_a Async::HTTP::Protocol::HTTP end + + it "exposes the supported protocol names" do + expect(subject.names).to be == ["h2", "http/1.1", "http/1.0"] + end + end + + with "configured protocols" do + let(:protocol) {subject.new(http1: Async::HTTP::Protocol::HTTP11, http2: Async::HTTP::Protocol::HTTP2)} + + it "exposes their supported protocol names" do + expect(protocol.names).to be == ["h2", "http/1.1"] + end end with "#protocol_for" do