|
43 | 43 | client.post("/", [[":authority", "foo"]]) |
44 | 44 | end.to raise_exception(Protocol::HTTP2::StreamError) |
45 | 45 | end |
| 46 | + |
| 47 | + with "a bad request header" do |
| 48 | + let(:app) do |
| 49 | + Protocol::HTTP::Middleware.for do |
| 50 | + @app_called = true |
| 51 | + Protocol::HTTP::Response[200] |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + it "keeps the connection reusable" do |
| 56 | + @app_called = false |
| 57 | + response = client.get("/", [["range", "bytes=4-1"]]) |
| 58 | + |
| 59 | + expect(response.status).to be == 400 |
| 60 | + expect(@app_called).to be == false |
| 61 | + |
| 62 | + response.finish |
| 63 | + response = client.get("/") |
| 64 | + |
| 65 | + expect(response.status).to be == 200 |
| 66 | + expect(@app_called).to be == true |
| 67 | + ensure |
| 68 | + response&.close |
| 69 | + end |
| 70 | + |
| 71 | + it "does not send response data for HEAD" do |
| 72 | + response = client.head("/", [["range", "bytes=4-1"]]) |
| 73 | + |
| 74 | + expect(response.status).to be == 400 |
| 75 | + expect(response.body.length).to be_nil |
| 76 | + expect(response.read).to be_nil |
| 77 | + ensure |
| 78 | + response&.close |
| 79 | + end |
| 80 | + |
| 81 | + it "terminates an unfinished request body" do |
| 82 | + body = Async::HTTP::Body::Writable.new |
| 83 | + response = client.post("/", [["range", "bytes=4-1"]], body) |
| 84 | + connection = response.connection |
| 85 | + |
| 86 | + expect(response.status).to be == 400 |
| 87 | + expect(response.read).to be == "Protocol::HTTP::Header::Range::ParseError" |
| 88 | + expect(response.stream).to be(:closed?) |
| 89 | + expect(connection.streams).to be(:empty?) |
| 90 | + expect(connection).to be(:reusable?) |
| 91 | + ensure |
| 92 | + body&.close |
| 93 | + response&.close |
| 94 | + end |
| 95 | + end |
| 96 | + |
| 97 | + with "a malformed request" do |
| 98 | + it "prioritizes protocol validation over bad request handling" do |
| 99 | + client.pool.acquire do |connection| |
| 100 | + response = connection.create_response |
| 101 | + response.stream.send_headers([ |
| 102 | + [":method", "GET"], |
| 103 | + [":path", "/"], |
| 104 | + ["range", "bytes=4-1"], |
| 105 | + ], ::Protocol::HTTP2::END_STREAM) |
| 106 | + |
| 107 | + expect do |
| 108 | + connection.read_response(response) |
| 109 | + end.to raise_exception(Protocol::HTTP2::StreamError).and( |
| 110 | + have_attributes(code: be == Protocol::HTTP2::Error::STREAM_CLOSED) |
| 111 | + ) |
| 112 | + end |
| 113 | + end |
| 114 | + end |
46 | 115 | end |
47 | 116 |
|
48 | 117 | with "closed streams" do |
|
0 commit comments