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
Constants
- DROP_BODY_RESPONSES
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/sinatra/base.rb 122 def initialize(*) 123 super 124 headers['Content-Type'] ||= 'text/html' 125 end
Public Instance Methods
body=(value)
click to toggle source
# File lib/sinatra/base.rb 127 def body=(value) 128 value = value.body while Rack::Response === value 129 @body = String === value ? [value.to_str] : value 130 end
each()
click to toggle source
Calls superclass method
# File lib/sinatra/base.rb 132 def each 133 block_given? ? super : enum_for(:each) 134 end
finish()
click to toggle source
# File lib/sinatra/base.rb 136 def finish 137 result = body 138 139 if drop_content_info? 140 headers.delete "Content-Length" 141 headers.delete "Content-Type" 142 end 143 144 if drop_body? 145 close 146 result = [] 147 end 148 149 if calculate_content_length? 150 # if some other code has already set Content-Length, don't muck with it 151 # currently, this would be the static file-handler 152 headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s 153 end 154 155 [status.to_i, headers, result] 156 end
Private Instance Methods
calculate_content_length?()
click to toggle source
# File lib/sinatra/base.rb 160 def calculate_content_length? 161 headers["Content-Type"] and not headers["Content-Length"] and Array === body 162 end
drop_body?()
click to toggle source
# File lib/sinatra/base.rb 168 def drop_body? 169 DROP_BODY_RESPONSES.include?(status.to_i) 170 end
drop_content_info?()
click to toggle source
# File lib/sinatra/base.rb 164 def drop_content_info? 165 status.to_i / 100 == 1 or drop_body? 166 end