|
18 | 18 | end |
19 | 19 |
|
20 | 20 | with "#wrap" do |
21 | | - let(:env) { {} } |
22 | | - let(:headers) { {} } |
| 21 | + let(:env) {Hash.new} |
| 22 | + let(:headers) {Hash.new} |
23 | 23 |
|
24 | 24 | it "handles nil body" do |
25 | 25 | expect(Console).to receive(:warn).and_return(nil) |
|
28 | 28 | expect(result).to be_nil |
29 | 29 | end |
30 | 30 |
|
| 31 | + with "head request" do |
| 32 | + it "wraps response with content-length and empty body" do |
| 33 | + headers["content-length"] = "123" |
| 34 | + |
| 35 | + result = subject.wrap(env, 200, headers, [], nil, true) |
| 36 | + |
| 37 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 38 | + expect(result.length).to be == 123 |
| 39 | + end |
| 40 | + |
| 41 | + it "wraps response with no content-length and empty body" do |
| 42 | + result = subject.wrap(env, 200, headers, [], nil, true) |
| 43 | + |
| 44 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 45 | + expect(result.length).to be == 0 |
| 46 | + end |
| 47 | + |
| 48 | + it "wraps response with content-length and nil body" do |
| 49 | + headers["content-length"] = "123" |
| 50 | + |
| 51 | + expect(Console).to receive(:warn).and_return(nil) |
| 52 | + result = subject.wrap(env, 200, headers, nil, nil, true) |
| 53 | + |
| 54 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 55 | + expect(result.length).to be == 123 |
| 56 | + end |
| 57 | + |
| 58 | + it "wraps response with no content-length and nil body" do |
| 59 | + expect(Console).to receive(:warn).and_return(nil) |
| 60 | + |
| 61 | + result = subject.wrap(env, 200, headers, nil, nil, true) |
| 62 | + |
| 63 | + expect(result).to be_nil |
| 64 | + end |
| 65 | + |
| 66 | + it "wraps response with content-length and body" do |
| 67 | + # We trust the appliation to provide the correct content-length, but this is usually validated at the transport layer. |
| 68 | + headers["content-length"] = "123" |
| 69 | + |
| 70 | + result = subject.wrap(env, 200, headers, ["body"], nil, true) |
| 71 | + |
| 72 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 73 | + expect(result.length).to be == 123 |
| 74 | + end |
| 75 | + end |
| 76 | + |
31 | 77 | with "non-empty body and no-content status" do |
32 | 78 | let(:mock_body) do |
33 | 79 | Protocol::HTTP::Body::Buffered.new(["content"]) |
|
0 commit comments