|
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 | + it "handles head request with content-length and empty body" do |
| 32 | + # Rack::Head will result in an enumerable body, and currently does not set content-length either. |
| 33 | + # So, it's up to the application to set the content-length header if they use `Rack::Head`. |
| 34 | + # Otherwise, we should basically ignore the body but retain the length if known/provided. |
| 35 | + headers["content-length"] = "123" |
| 36 | + |
| 37 | + result = subject.wrap(env, 200, headers, [], nil, true) |
| 38 | + |
| 39 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 40 | + expect(result.length).to be == 123 |
| 41 | + end |
| 42 | + |
| 43 | + it "handles head request with no content-length and empty body" do |
| 44 | + result = subject.wrap(env, 200, headers, [], nil, true) |
| 45 | + |
| 46 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 47 | + expect(result.length).to be == 0 |
| 48 | + end |
| 49 | + |
| 50 | + it "handles head request with content-length and nil body" do |
| 51 | + headers["content-length"] = "123" |
| 52 | + |
| 53 | + expect(Console).to receive(:warn).and_return(nil) |
| 54 | + result = subject.wrap(env, 200, headers, nil, nil, true) |
| 55 | + |
| 56 | + expect(result).to be_a(Protocol::HTTP::Body::Head) |
| 57 | + expect(result.length).to be == 123 |
| 58 | + end |
| 59 | + |
| 60 | + it "handles head request with no content-length and nil body" do |
| 61 | + expect(Console).to receive(:warn).and_return(nil) |
| 62 | + |
| 63 | + result = subject.wrap(env, 200, headers, nil, nil, true) |
| 64 | + |
| 65 | + expect(result).to be_nil |
| 66 | + end |
| 67 | + |
31 | 68 | with "non-empty body and no-content status" do |
32 | 69 | let(:mock_body) do |
33 | 70 | Protocol::HTTP::Body::Buffered.new(["content"]) |
|
0 commit comments