mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed problem with send_file and WEBrick using stdout #1812
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2274 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
3c0129af6d
commit
3754822f43
3 changed files with 10 additions and 15 deletions
|
@ -145,7 +145,7 @@ module ActionController #:nodoc:
|
|||
if @cgi.send(:env_table)['REQUEST_METHOD'] == 'HEAD'
|
||||
return
|
||||
elsif @body.respond_to?(:call)
|
||||
@body.call(self)
|
||||
@body.call(self, output)
|
||||
else
|
||||
output.write(@body)
|
||||
end
|
||||
|
|
|
@ -61,20 +61,20 @@ module ActionController #:nodoc:
|
|||
@performed_render = false
|
||||
|
||||
if options[:stream]
|
||||
render :text => Proc.new {
|
||||
render :text => Proc.new { |response, output|
|
||||
logger.info "Streaming file #{path}" unless logger.nil?
|
||||
len = options[:buffer_size] || 4096
|
||||
File.open(path, 'rb') do |file|
|
||||
if $stdout.respond_to?(:syswrite)
|
||||
if output.respond_to?(:syswrite)
|
||||
begin
|
||||
while true
|
||||
$stdout.syswrite file.sysread(len)
|
||||
output.syswrite(file.sysread(len))
|
||||
end
|
||||
rescue EOFError
|
||||
end
|
||||
else
|
||||
while buf = file.read(len)
|
||||
$stdout.write buf
|
||||
output.write(buf)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,16 +47,11 @@ class SendFileTest < Test::Unit::TestCase
|
|||
assert_not_nil response
|
||||
assert_kind_of Proc, response.body
|
||||
|
||||
old_stdout = $stdout
|
||||
begin
|
||||
require 'stringio'
|
||||
$stdout = StringIO.new
|
||||
$stdout.binmode
|
||||
assert_nothing_raised { response.body.call }
|
||||
assert_equal file_data, $stdout.string
|
||||
ensure
|
||||
$stdout = old_stdout
|
||||
end
|
||||
require 'stringio'
|
||||
output = StringIO.new
|
||||
output.binmode
|
||||
assert_nothing_raised { response.body.call(response, output) }
|
||||
assert_equal file_data, output.string
|
||||
end
|
||||
|
||||
def test_data
|
||||
|
|
Loading…
Reference in a new issue