Class | Sinatra::Response |
In: |
lib/sinatra/base.rb
|
Parent: | Rack::Response |
The response object. See Rack::Response and Rack::ResponseHelpers for more info: rack.rubyforge.org/doc/classes/Rack/Response.html rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
# File lib/sinatra/base.rb, line 34 34: def initialize 35: @status, @body = 200, [] 36: @header = Rack::Utils::HeaderHash.new({'Content-Type' => 'text/html'}) 37: end
# File lib/sinatra/base.rb, line 44 44: def finish 45: @body = block if block_given? 46: if [204, 304].include?(status.to_i) 47: header.delete "Content-Type" 48: [status.to_i, header.to_hash, []] 49: else 50: body = @body || [] 51: body = [body] if body.respond_to? :to_str 52: if body.respond_to?(:to_ary) 53: header["Content-Length"] = body.to_ary. 54: inject(0) { |len, part| len + part.bytesize }.to_s 55: end 56: [status.to_i, header.to_hash, body] 57: end 58: end