class Sinatra::Response

The response object. See Rack::Response and Rack::Response::Helpers for more info: rack.rubyforge.org/doc/classes/Rack/Response.html rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/sinatra/base.rb, line 117
def initialize(*)
  super
  headers['Content-Type'] ||= 'text/html'
end

Public Instance Methods

body=(value) click to toggle source
# File lib/sinatra/base.rb, line 122
def body=(value)
  value = value.body while Rack::Response === value
  @body = String === value ? [value.to_str] : value
end
each() click to toggle source
Calls superclass method
# File lib/sinatra/base.rb, line 127
def each
  block_given? ? super : enum_for(:each)
end
finish() click to toggle source
# File lib/sinatra/base.rb, line 131
def finish
  result = body

  if drop_content_info?
    headers.delete "Content-Length"
    headers.delete "Content-Type"
  end

  if drop_body?
    close
    result = []
  end

  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
  end

  [status.to_i, headers, result]
end

Private Instance Methods

calculate_content_length?() click to toggle source
# File lib/sinatra/base.rb, line 155
def calculate_content_length?
  headers["Content-Type"] and not headers["Content-Length"] and Array === body
end
drop_body?() click to toggle source
# File lib/sinatra/base.rb, line 163
def drop_body?
  [204, 205, 304].include?(status.to_i)
end
drop_content_info?() click to toggle source
# File lib/sinatra/base.rb, line 159
def drop_content_info?
  status.to_i / 100 == 1 or drop_body?
end