Skip to content

Commit

Permalink
Merge pull request #49 from quark-zju/rails3
Browse files Browse the repository at this point in the history
Set content-length correctly in ruby 1.9
  • Loading branch information
knzconnor committed Apr 3, 2012
2 parents 3328638 + bc3d020 commit 1e6d336
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/rack/bug/toolbar.rb
@@ -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 module Rack
class Bug class Bug
class Toolbar class Toolbar
Expand Down Expand Up @@ -49,7 +58,7 @@ def inject_toolbar


full_body.sub! /<\/body>/, toolbar + "</body>" 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 # Ensure that browser does
@response["Etag"] = "" @response["Etag"] = ""
Expand Down
4 changes: 3 additions & 1 deletion spec/rack/toolbar_spec.rb
Expand Up @@ -8,7 +8,9 @@


it "updates the Content-Length" do it "updates the Content-Length" do
response = get "/" 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 end


it "serves the Rack::Bug assets under /__rack_bug__/" do it "serves the Rack::Bug assets under /__rack_bug__/" do
Expand Down

0 comments on commit 1e6d336

Please sign in to comment.