|
27 | 27 | server.write_body("HTTP/1.0", body, false, trailer) |
28 | 28 | end |
29 | 29 |
|
30 | | - it "ignores trailers with content length" do |
31 | | - expect(server).to receive(:write_fixed_length_body) |
| 30 | + it "uses chunked encoding when trailers are present even with content length" do |
| 31 | + expect(server).to receive(:write_chunked_body).with(body, false, trailer) |
32 | 32 | server.write_body("HTTP/1.1", body, false, trailer) |
33 | 33 | end |
34 | 34 |
|
| 35 | + it "uses fixed length when no trailers" do |
| 36 | + expect(server).to receive(:write_fixed_length_body) |
| 37 | + server.write_body("HTTP/1.1", body, false, nil) |
| 38 | + end |
| 39 | + |
35 | 40 | it "uses chunked encoding when given trailers without content length" do |
36 | 41 | expect(body).to receive(:length).and_return(nil) |
37 | 42 | trailer["foo"] = "bar" |
|
51 | 56 | # Headers are updated: |
52 | 57 | expect(headers).to be == {"foo" => ["bar"]} |
53 | 58 | end |
| 59 | + |
| 60 | + it "uses chunked encoding when given trailers with empty body" do |
| 61 | + empty_body = Protocol::HTTP::Body::Buffered.new |
| 62 | + trailer["grpc-status"] = "2" |
| 63 | + |
| 64 | + expect(server).to receive(:write_chunked_body).with(empty_body, false, trailer) |
| 65 | + server.write_body("HTTP/1.1", empty_body, false, trailer) |
| 66 | + end |
| 67 | + |
| 68 | + it "sends trailers with empty body (round-trip)" do |
| 69 | + empty_body = Protocol::HTTP::Body::Buffered.new |
| 70 | + trailer["grpc-status"] = "2" |
| 71 | + |
| 72 | + server.write_response("HTTP/1.1", 200, {}) |
| 73 | + server.write_body("HTTP/1.1", empty_body, false, trailer) |
| 74 | + |
| 75 | + version, status, reason, headers, body = client.read_response("GET") |
| 76 | + |
| 77 | + expect(version).to be == "HTTP/1.1" |
| 78 | + expect(status).to be == 200 |
| 79 | + expect(headers).to be == {} |
| 80 | + |
| 81 | + # Read all of the response body, including trailers: |
| 82 | + body.join |
| 83 | + |
| 84 | + # Headers are updated: |
| 85 | + expect(headers).to be == {"grpc-status" => ["2"]} |
| 86 | + end |
| 87 | + |
| 88 | + it "uses chunked encoding when given trailers with known body length" do |
| 89 | + trailer["grpc-status"] = "0" |
| 90 | + |
| 91 | + expect(server).to receive(:write_chunked_body).with(body, false, trailer) |
| 92 | + server.write_body("HTTP/1.1", body, false, trailer) |
| 93 | + end |
| 94 | + |
| 95 | + it "sends trailers with known body length (round-trip)" do |
| 96 | + trailer["grpc-status"] = "0" |
| 97 | + |
| 98 | + server.write_response("HTTP/1.1", 200, {}) |
| 99 | + server.write_body("HTTP/1.1", body, false, trailer) |
| 100 | + |
| 101 | + version, status, reason, headers, body = client.read_response("GET") |
| 102 | + |
| 103 | + expect(version).to be == "HTTP/1.1" |
| 104 | + expect(status).to be == 200 |
| 105 | + expect(headers).to be == {} |
| 106 | + |
| 107 | + # Read all of the response body, including trailers: |
| 108 | + body.join |
| 109 | + |
| 110 | + # Headers are updated: |
| 111 | + expect(headers).to be == {"grpc-status" => ["0"]} |
| 112 | + end |
54 | 113 | end |
55 | 114 | end |
0 commit comments