Skip to content

Instantly share code, notes, and snippets.

@samwgoldman
Created April 27, 2012 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwgoldman/2513265 to your computer and use it in GitHub Desktop.
Save samwgoldman/2513265 to your computer and use it in GitHub Desktop.
webmachine-ruby chunked response with rack adapter streaming
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