Permalink
Browse files

Merge pull request #49 from quark-zju/rails3

Set content-length correctly in ruby 1.9
  • Loading branch information...
2 parents 3328638 + bc3d020 commit 1e6d33664fb21a5f08836e5d8a9d7bfcc47c8d81 @knzconnor knzconnor committed Apr 3, 2012
Showing with 13 additions and 2 deletions.
  1. +10 −1 lib/rack/bug/toolbar.rb
  2. +3 −1 spec/rack/toolbar_spec.rb
View
@@ -1,3 +1,12 @@
+# we need 'bytesize' for String, which does not exists and is 'size' in Ruby 1.8
+unless String.instance_methods.include? :bytesize
+ class String
+ def bytesize
+ size
+ end
+ end
+end
+
module Rack
class Bug
class Toolbar
@@ -49,7 +58,7 @@ def inject_toolbar
full_body.sub! /<\/body>/, toolbar + "</body>"
- @response["Content-Length"] = full_body.size.to_s
+ @response["Content-Length"] = full_body.bytesize.to_s
# Ensure that browser does
@response["Etag"] = ""
@@ -8,7 +8,9 @@
it "updates the Content-Length" do
response = get "/"
- response["Content-Length"].should == response.body.size.to_s
+ body = response.body
+ content_length = body.respond_to?(:bytesize) ? body.bytesize : body.size
+ response["Content-Length"].should == content_length
end
it "serves the Rack::Bug assets under /__rack_bug__/" do

0 comments on commit 1e6d336

Please sign in to comment.