|
| 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