|
13 | 13 | expect(headers["Accept"]).to eq "application/json" |
14 | 14 | end |
15 | 15 |
|
16 | | - it "normalizes header name" do |
| 16 | + it "allows retrieval via normalized header name" do |
17 | 17 | headers.set :content_type, "application/json" |
18 | 18 | expect(headers["Content-Type"]).to eq "application/json" |
19 | 19 | end |
|
54 | 54 | expect(headers["Accept"]).to eq "application/json" |
55 | 55 | end |
56 | 56 |
|
57 | | - it "normalizes header name" do |
| 57 | + it "allows retrieval via normalized header name" do |
58 | 58 | headers[:content_type] = "application/json" |
59 | 59 | expect(headers["Content-Type"]).to eq "application/json" |
60 | 60 | end |
|
80 | 80 | expect(headers["Content-Type"]).to be_nil |
81 | 81 | end |
82 | 82 |
|
83 | | - it "normalizes header name" do |
| 83 | + it "removes header that matches normalized version of specified name" do |
84 | 84 | headers.delete :content_type |
85 | 85 | expect(headers["Content-Type"]).to be_nil |
86 | 86 | end |
|
104 | 104 | expect(headers["Accept"]).to eq "application/json" |
105 | 105 | end |
106 | 106 |
|
107 | | - it "normalizes header name" do |
| 107 | + it "allows retrieval via normalized header name" do |
108 | 108 | headers.add :content_type, "application/json" |
109 | 109 | expect(headers["Content-Type"]).to eq "application/json" |
110 | 110 | end |
111 | 111 |
|
112 | 112 | it "appends new value if header exists" do |
113 | | - headers.add :set_cookie, "hoo=ray" |
| 113 | + headers.add "Set-Cookie", "hoo=ray" |
114 | 114 | headers.add :set_cookie, "woo=hoo" |
115 | 115 | expect(headers["Set-Cookie"]).to eq %w[hoo=ray woo=hoo] |
116 | 116 | end |
|
137 | 137 | expect { headers.add "foo", "bar\nEvil-Header: evil-value" }. |
138 | 138 | to raise_error HTTP::HeaderError |
139 | 139 | end |
| 140 | + |
| 141 | + it "fails when header name is not a String or Symbol" do |
| 142 | + expect { headers.add 2, "foo" }. |
| 143 | + to raise_error HTTP::HeaderError |
| 144 | + end |
140 | 145 | end |
141 | 146 |
|
142 | 147 | describe "#get" do |
|
314 | 319 | ) |
315 | 320 | end |
316 | 321 |
|
| 322 | + it "yields header keys specified as symbols in normalized form" do |
| 323 | + keys = headers.each.map(&:first) |
| 324 | + expect(keys).to eq(["Set-Cookie", "Content-Type", "Set-Cookie"]) |
| 325 | + end |
| 326 | + |
| 327 | + it "yields headers specified as strings without conversion" do |
| 328 | + headers.add "X_kEy", "value" |
| 329 | + keys = headers.each.map(&:first) |
| 330 | + expect(keys).to eq(["Set-Cookie", "Content-Type", "Set-Cookie", "X_kEy"]) |
| 331 | + end |
| 332 | + |
317 | 333 | it "returns self instance if block given" do |
318 | 334 | expect(headers.each { |*| }).to be headers |
319 | 335 | end |
|
490 | 506 | end |
491 | 507 |
|
492 | 508 | context "with duplicate header keys (mixed case)" do |
493 | | - let(:headers) { {"Set-Cookie" => "hoo=ray", "set-cookie" => "woo=hoo"} } |
| 509 | + let(:headers) { {"Set-Cookie" => "hoo=ray", "set_cookie" => "woo=hoo", :set_cookie => "ta=da"} } |
494 | 510 |
|
495 | 511 | it "adds all headers" do |
496 | 512 | expect(described_class.coerce(headers).to_a). |
497 | 513 | to match_array( |
498 | 514 | [ |
499 | 515 | %w[Set-Cookie hoo=ray], |
500 | | - %w[Set-Cookie woo=hoo] |
| 516 | + %w[set_cookie woo=hoo], |
| 517 | + %w[Set-Cookie ta=da] |
501 | 518 | ] |
502 | 519 | ) |
503 | 520 | end |
|
0 commit comments