Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created October 25, 2013 22:50
Show Gist options
  • Save thinkerbot/7163006 to your computer and use it in GitHub Desktop.
Save thinkerbot/7163006 to your computer and use it in GitHub Desktop.
Rack streaming via puma.
# puma
# curl http://localhost:9292/
#
# Note chrome buffers like 1024 or so... meaning the first lots will look missing.
run lambda { |env|
body = lambda { |io|
io.sync = true
10.times do |i|
n = 2
str = (i.to_s * (n - 1)) + "\n"
io.write "#{str.length.to_s 16}\r\n"
io.write "#{str}\r\n"
sleep 1
end
io.write "0\r\n"
io.write "\r\n"
io.close
}
headers = {
"Content-Type" => "text/plain",
"Cache-Control" => "no-cache",
"Transfer-Encoding" => "chunked",
'rack.hijack' => body
}
[200, headers, nil]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment