1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2019-2026, by Samuel Williams.
# Copyright, 2024, by Thomas Morgan.
require "protocol/http/headers"
require "protocol/http/cookie"
describe Protocol::HTTP::Header::Connection do
let(:header) {subject.parse(description)}
with "close" do
it "should indiciate connection will be closed" do
expect(header).to be(:close?)
end
it "should indiciate connection will not be keep-alive" do
expect(header).not.to be(:keep_alive?)
end
end
with "keep-alive" do
it "should indiciate connection will not be closed" do
expect(header).not.to be(:close?)
end
it "should indiciate connection is not keep-alive" do
expect(header).to be(:keep_alive?)
end
end
with "close, keep-alive" do
it "should prioritize close over keep-alive" do
expect(header).to be(:close?)
expect(header).not.to be(:keep_alive?)
end
end
with "upgrade" do
it "should indiciate connection can be upgraded" do
expect(header).to be(:upgrade?)
end
end
with "#<<" do
let(:header) {subject.new}
it "can append values" do
header << "close"
expect(header).to be(:close?)
header << "upgrade"
expect(header).to be(:upgrade?)
expect(header.to_s).to be == "close,upgrade"
end
end
with ".coerce" do
it "normalizes array values to lowercase" do
header = subject.coerce(["CLOSE", "UPGRADE"])
expect(header).to be(:include?, "close")
expect(header).to be(:include?, "upgrade")
expect(header).not.to be(:include?, "CLOSE")
end
it "normalizes string values to lowercase" do
header = subject.coerce("CLOSE, UPGRADE")
expect(header).to be(:include?, "close")
expect(header).to be(:include?, "upgrade")
end
end
with ".new" do
it "preserves case when given array" do
header = subject.new(["CLOSE", "UPGRADE"])
expect(header).to be(:include?, "CLOSE")
expect(header).to be(:include?, "UPGRADE")
end
it "normalizes when given string (backward compatibility)" do
header = subject.new("CLOSE, UPGRADE")
expect(header).to be(:include?, "close")
expect(header).to be(:include?, "upgrade")
end
it "raises ArgumentError for invalid value types" do
expect{subject.new(123)}.to raise_exception(ArgumentError)
end
end
end
|