class Sinatra::Response

The response object. See Rack::Response and Rack::Response::Helpers for more info: rubydoc.info/github/rack/rack/master/Rack/Response rubydoc.info/github/rack/rack/master/Rack/Response/Helpers

Constants

DROP_BODY_RESPONSES

Public Class Methods

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

Public Instance Methods

body=(value) click to toggle source
    # File lib/sinatra/base.rb
141 def body=(value)
142   value = value.body while Rack::Response === value
143   @body = String === value ? [value.to_str] : value
144 end
each() click to toggle source
Calls superclass method
    # File lib/sinatra/base.rb
146 def each
147   block_given? ? super : enum_for(:each)
148 end
finish() click to toggle source
    # File lib/sinatra/base.rb
150 def finish
151   result = body
152 
153   if drop_content_info?
154     headers.delete "Content-Length"
155     headers.delete "Content-Type"
156   end
157 
158   if drop_body?
159     close
160     result = []
161   end
162 
163   if calculate_content_length?
164     # if some other code has already set Content-Length, don't muck with it
165     # currently, this would be the static file-handler
166     headers["Content-Length"] = body.inject(0) { |l, p| l + p.bytesize }.to_s
167   end
168 
169   [status.to_i, headers, result]
170 end

Private Instance Methods

calculate_content_length?() click to toggle source
    # File lib/sinatra/base.rb
174 def calculate_content_length?
175   headers["Content-Type"] and not headers["Content-Length"] and Array === body
176 end
drop_body?() click to toggle source
    # File lib/sinatra/base.rb
182 def drop_body?
183   DROP_BODY_RESPONSES.include?(status.to_i)
184 end
drop_content_info?() click to toggle source
    # File lib/sinatra/base.rb
178 def drop_content_info?
179   status.to_i / 100 == 1 or drop_body?
180 end