Permalink
Browse files

Ruby 1.9 compat: call bytesize for content_length

[#1881 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 5581229 commit ae36fcedce1ffcf4f3331b444ea1779987c6615a @libc libc committed with jeremy Feb 5, 2009
Showing with 16 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_controller/response.rb
  2. +15 −0 actionpack/test/controller/rack_test.rb
@@ -236,7 +236,7 @@ def set_content_length!
elsif length = headers['Content-Length']
headers['Content-Length'] = length.to_s
elsif !body.respond_to?(:call) && (!status || status.to_s[0..2] != '304')
- headers["Content-Length"] = body.size.to_s
+ headers["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
end
end
@@ -228,6 +228,21 @@ def test_simple_output
assert_equal ["Hello, World!"], parts
end
+ def test_utf8_output
+ @response.body = [1090, 1077, 1089, 1090].pack("U*")
+ @response.prepare!
+
+ status, headers, body = @response.to_a
+ assert_equal 200, status
+ assert_equal({
+ "Content-Type" => "text/html; charset=utf-8",
+ "Cache-Control" => "private, max-age=0, must-revalidate",
+ "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
+ "Set-Cookie" => [],
+ "Content-Length" => "8"
+ }, headers)
+ end
+
def test_streaming_block
@response.body = Proc.new do |response, output|
5.times { |n| output.write(n) }

0 comments on commit ae36fce

Please sign in to comment.