This commit is contained in:
parent
78784f9391
commit
5558cc2c88
|
@ -63,8 +63,8 @@ module Sinatra
|
||||||
# http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
|
# http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
|
||||||
class Response < Rack::Response
|
class Response < Rack::Response
|
||||||
def body=(value)
|
def body=(value)
|
||||||
value = value.body while value.respond_to? :body and value.body != value
|
value = value.body while Rack::Response === value
|
||||||
@body = value.respond_to?(:to_str) ? [value.to_str] : value
|
@body = String === value ? [value.to_str] : value
|
||||||
end
|
end
|
||||||
|
|
||||||
def each
|
def each
|
||||||
|
@ -75,7 +75,7 @@ module Sinatra
|
||||||
if status.to_i / 100 == 1
|
if status.to_i / 100 == 1
|
||||||
headers.delete "Content-Length"
|
headers.delete "Content-Length"
|
||||||
headers.delete "Content-Type"
|
headers.delete "Content-Type"
|
||||||
elsif body.respond_to? :to_ary and not [204, 304].include?(status.to_i)
|
elsif Array === body and not [204, 304].include?(status.to_i)
|
||||||
headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
|
headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
|
||||||
end
|
end
|
||||||
super
|
super
|
||||||
|
@ -614,7 +614,7 @@ module Sinatra
|
||||||
invoke { error_block!(response.status) }
|
invoke { error_block!(response.status) }
|
||||||
|
|
||||||
unless @response['Content-Type']
|
unless @response['Content-Type']
|
||||||
if body.respond_to? :to_ary and body[0].respond_to? :content_type
|
if Array === body and body[0].respond_to? :content_type
|
||||||
content_type body[0].content_type
|
content_type body[0].content_type
|
||||||
else
|
else
|
||||||
content_type :html
|
content_type :html
|
||||||
|
@ -700,7 +700,7 @@ module Sinatra
|
||||||
# Revert params afterwards.
|
# Revert params afterwards.
|
||||||
#
|
#
|
||||||
# Returns pass block.
|
# Returns pass block.
|
||||||
def process_route(pattern, keys, conditions, block = nil)
|
def process_route(pattern, keys, conditions, block = nil, values = nil)
|
||||||
@original_params ||= @params
|
@original_params ||= @params
|
||||||
route = @request.path_info
|
route = @request.path_info
|
||||||
route = '/' if route.empty? and not settings.empty_path_info?
|
route = '/' if route.empty? and not settings.empty_path_info?
|
||||||
|
|
|
@ -40,6 +40,15 @@ class ResponseTest < Test::Unit::TestCase
|
||||||
assert_equal @response.body, body.body
|
assert_equal @response.body, body.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not call #to_ary or #inject on the body' do
|
||||||
|
object = Object.new
|
||||||
|
def object.inject(*) fail 'called' end
|
||||||
|
def object.to_ary(*) fail 'called' end
|
||||||
|
def object.each(*) end
|
||||||
|
@response.body = object
|
||||||
|
assert @response.finish
|
||||||
|
end
|
||||||
|
|
||||||
it 'does not nest a Sinatra::Response' do
|
it 'does not nest a Sinatra::Response' do
|
||||||
@response.body = Sinatra::Response.new ["foo"]
|
@response.body = Sinatra::Response.new ["foo"]
|
||||||
assert_equal @response.body, ["foo"]
|
assert_equal @response.body, ["foo"]
|
||||||
|
|
Loading…
Reference in New Issue