Skip to content

Commit

Permalink
Ruby 1.9: fix Content-Length for multibyte send_data streaming
Browse files Browse the repository at this point in the history
[#2661 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
kanmeiban authored and jeremy committed Aug 2, 2009
1 parent 7244425 commit dc559f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*2.3.4 (pending)*

* Ruby 1.9: fix Content-Length for multibyte send_data streaming. #2661 [Sava Chankov]


*2.3.3 (July 12, 2009)*

* Fixed that TestResponse.cookies was returning cookies unescaped #1867 [Doug McInnes]
Expand Down
4 changes: 3 additions & 1 deletion actionpack/lib/action_controller/streaming.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support/core_ext/string/bytesize'

module ActionController #:nodoc:
# Methods for sending arbitrary data and for streaming files to the browser,
# instead of rendering.
Expand Down Expand Up @@ -137,7 +139,7 @@ def send_file(path, options = {}) #:doc:
# instead. See ActionController::Base#render for more information.
def send_data(data, options = {}) #:doc:
logger.info "Sending data #{options[:filename]}" if logger
send_file_headers! options.merge(:length => data.size)
send_file_headers! options.merge(:length => data.bytesize)
@performed_render = false
render :status => options[:status], :text => data
end
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/controller/send_file_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
require 'abstract_unit'

module TestFileUtils
Expand All @@ -15,6 +16,7 @@ def options() @options ||= {} end

def file() send_file(file_path, options) end
def data() send_data(file_data, options) end
def multibyte_text_data() send_data("Кирилица\n祝您好運", options) end

def rescue_action(e) raise end
end
Expand Down Expand Up @@ -158,4 +160,11 @@ def test_send_file_headers_with_bad_symbol
assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status
end
end

def test_send_data_content_length_header
@controller.headers = {}
@controller.options = { :type => :text, :filename => 'file_with_utf8_text' }
process('multibyte_text_data')
assert_equal '29', @controller.headers['Content-Length']
end
end

0 comments on commit dc559f2

Please sign in to comment.