diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 696be772..24ca0a76 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -287,8 +287,18 @@ module Sinatra # The close parameter specifies whether Stream#close should be called # after the block has been executed. This is only relevant for evented # servers like Thin or Rainbows. - def stream(keep_open = false, &block) + def stream(keep_open = false) scheduler = env['async.callback'] ? EventMachine : Stream + current = @params.dup + block = proc do |out| + begin + original, @params = @params, current + yield(out) + ensure + @params = original if original + end + end + body Stream.new(scheduler, keep_open, &block) end diff --git a/test/streaming_test.rb b/test/streaming_test.rb index 9448d358..20bc41cf 100644 --- a/test/streaming_test.rb +++ b/test/streaming_test.rb @@ -112,4 +112,12 @@ class StreamingTest < Test::Unit::TestCase stream = Stream.new { |out| out.callback { out.close }} stream.each { |str| } end + + it 'gives access to route specific params' do + mock_app do + get('/:name') { stream { |o| o << params[:name] }} + end + get '/foo' + assert_body 'foo' + end end