diff --git lib/sinatra/base.rb lib/sinatra/base.rb
index 819dd37..d3ff4e5 100644
--- lib/sinatra/base.rb
+++ lib/sinatra/base.rb
@@ -151,7 +151,7 @@ module Sinatra
if calculate_content_length?
# if some other code has already set Content-Length, don't muck with it
# currently, this would be the static file-handler
- headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
+ headers["Content-Length"] = body.inject(0) { |l, p| l + p.bytesize }.to_s
end
[status.to_i, headers, result]
@@ -240,7 +240,11 @@ module Sinatra
def block.each; yield(call) end
response.body = block
elsif value
- headers.delete 'Content-Length' unless request.head? || value.is_a?(Rack::File) || value.is_a?(Stream)
+ # Rack 2.0 returns a Rack::File::Iterator here instead of
+ # Rack::File as it was in the previous API.
+ unless request.head? || value.is_a?(Rack::File::Iterator) || value.is_a?(Stream)
+ headers.delete 'Content-Length'
+ end
response.body = value
else
response.body
@@ -363,13 +367,13 @@ module Sinatra
last_modified opts[:last_modified] if opts[:last_modified]
- file = Rack::File.new nil
- file.path = path
- result = file.serving env
+ file = Rack::File.new(File.dirname(settings.app_file))
+ result = file.serving(request, path)
+
result[1].each { |k,v| headers[k] ||= v }
headers['Content-Length'] = result[1]['Content-Length']
opts[:status] &&= Integer(opts[:status])
- halt opts[:status] || result[0], result[2]
+ halt (opts[:status] || result[0]), result[2]
rescue Errno::ENOENT
not_found
end
@@ -1065,6 +1069,7 @@ module Sinatra
# Run the block with 'throw :halt' support and apply result to the response.
def invoke
res = catch(:halt) { yield }
+
res = [res] if Fixnum === res or String === res
if Array === res and Fixnum === res.first
res = res.dup
diff --git lib/sinatra/show_exceptions.rb lib/sinatra/show_exceptions.rb
index 2e3069f..2988cc4 100644
--- lib/sinatra/show_exceptions.rb
+++ lib/sinatra/show_exceptions.rb
@@ -44,7 +44,7 @@ module Sinatra
500,
{
"Content-Type" => content_type,
- "Content-Length" => Rack::Utils.bytesize(body.join).to_s
+ "Content-Length" => body.join.bytesize.to_s
},
body
]
diff --git test/settings_test.rb test/settings_test.rb
index 7ec03c6..1b135f5 100644
--- test/settings_test.rb
+++ test/settings_test.rb
@@ -244,7 +244,7 @@ class SettingsTest < Minitest::Test
get '/'
assert_equal 500, status
assert body.include?("StandardError")
- assert body.include?("show_exceptions
setting")
+ assert body.include?("Rack::ShowExceptions
")
end
it 'does not override app-specified error handling when set to :after_handler' do