Created
April 27, 2012 21:13
-
-
Save samwgoldman/2513265 to your computer and use it in GitHub Desktop.
webmachine-ruby chunked response with rack adapter streaming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "webmachine" | |
require "webmachine/adapters/rack" | |
class TestResource < Webmachine::Resource | |
def to_html | |
parts = %w{Hello, World!} | |
Fiber.new do | |
parts.each do |part| | |
Fiber.yield part | |
sleep 0.5 | |
end | |
nil | |
end | |
end | |
end | |
App = Webmachine::Application.new do |app| | |
app.routes do | |
add [], TestResource | |
end | |
end | |
App.configure do |config| | |
config.adapter = :Rack | |
config.adapter_options { :server => "mongrel" } # or another server supporting streaming | |
end | |
App.run | |
# curl -v -N --raw http://localhost:8080/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment