Skip to content

Commit fbd84e8

Browse files
Make HTTP/1.0 persistence assertion meaningful and pin read_body framing checks without a version.
1 parent 180b7c5 commit fbd84e8

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎test/protocol/http1/connection.rb‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
end
182182

183183
it "fails with HTTP/1.0 request with transfer-encoding and content-length" do
184-
client.stream.write "GET / HTTP/1.0\r\nHost: localhost\r\nContent-Length: 11\r\nTransfer-Encoding: chunked\r\n\r\nHello World"
184+
client.stream.write "GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\nContent-Length: 11\r\nTransfer-Encoding: chunked\r\n\r\nHello World"
185185
client.stream.close
186186

187187
expect do
@@ -626,6 +626,31 @@
626626
end
627627
end
628628

629+
with "#read_body" do
630+
# Callers using the original signature do not pass a version, so framing must still be validated without it.
631+
it "reads chunked request body without a version" do
632+
body = server.read_body({"transfer-encoding" => ["chunked"]}, false)
633+
634+
expect(body).to be_a(Protocol::HTTP1::Body::Chunked)
635+
expect(server).to be(:persistent)
636+
end
637+
638+
it "fails with non-chunked request transfer-encoding without a version" do
639+
expect do
640+
server.read_body({"transfer-encoding" => ["gzip"]}, false)
641+
end.to raise_exception(Protocol::HTTP1::BadRequest, message: be =~ /must be chunked/)
642+
643+
expect(server).not.to be(:persistent)
644+
end
645+
646+
it "reads non-chunked response transfer-encoding until closed without a version" do
647+
body = client.read_body({"transfer-encoding" => ["gzip"]}, true)
648+
649+
expect(body).to be_a(Protocol::HTTP1::Body::Remainder)
650+
expect(client).not.to be(:persistent)
651+
end
652+
end
653+
629654
with "#write_chunked_body" do
630655
let(:chunks) {["Hello", "World"]}
631656
let(:body) {::Protocol::HTTP::Body::Buffered.wrap(chunks)}

0 commit comments

Comments
 (0)