add route to test chunked encoding

This commit is contained in:
Ryan Cavicchioni 2025-03-09 15:38:34 -05:00
parent 86ba2e6c1a
commit b2e4fcbce1
Signed by: ryanc
SSH Key Fingerprint: SHA256:KbXiwUnZnHFwFtt3Bytd+F3FN9pPHn1Z1cxMIE1TPbg

9
app.rb
View File

@ -427,11 +427,14 @@ route :delete, :get, :patch, :post, :put, "/status/:code" do
end
get "/chunked/:delay" do
content_type "application/x-ndjson"
delay = Float(params[:delay])
stream do |out|
out << "Hello, world!\n"
sleep delay
out << "Hello, world!\n"
30.times do |i|
out << jsonify({id: i, message: i % 2 == 0 ? "tick" : "tock"})
sleep delay
end
end
end