Class | Sinatra::Response |
In: |
lib/sinatra/base.rb
|
Parent: | Rack::Response |
# File lib/sinatra/base.rb, line 27 27: def initialize 28: @status, @body = 200, [] 29: @header = Rack::Utils::HeaderHash.new({'Content-Type' => 'text/html'}) 30: end
# File lib/sinatra/base.rb, line 37 37: def finish 38: @body = block if block_given? 39: if [204, 304].include?(status.to_i) 40: header.delete "Content-Type" 41: [status.to_i, header.to_hash, []] 42: else 43: body = @body || [] 44: body = [body] if body.respond_to? :to_str 45: if header["Content-Length"].nil? && body.respond_to?(:to_ary) 46: header["Content-Length"] = body.to_ary. 47: inject(0) { |len, part| len + part.length }.to_s 48: end 49: [status.to_i, header.to_hash, body] 50: end 51: end