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 Instance Methods
body=(value)
click to toggle source
# File lib/sinatra/base.rb 165 def body=(value) 166 value = value.body while Rack::Response === value 167 @body = String === value ? [value.to_str] : value 168 end
each()
click to toggle source
Calls superclass method
# File lib/sinatra/base.rb 170 def each 171 block_given? ? super : enum_for(:each) 172 end
finish()
click to toggle source
# File lib/sinatra/base.rb 174 def finish 175 result = body 176 177 if drop_content_info? 178 headers.delete "Content-Length" 179 headers.delete "Content-Type" 180 end 181 182 if drop_body? 183 close 184 result = [] 185 end 186 187 if calculate_content_length? 188 # if some other code has already set Content-Length, don't muck with it 189 # currently, this would be the static file-handler 190 headers["Content-Length"] = body.map(&:bytesize).reduce(0, :+).to_s 191 end 192 193 [status, headers, result] 194 end
Private Instance Methods
calculate_content_length?()
click to toggle source
# File lib/sinatra/base.rb 198 def calculate_content_length? 199 headers["Content-Type"] and not headers["Content-Length"] and Array === body 200 end
drop_body?()
click to toggle source
# File lib/sinatra/base.rb 206 def drop_body? 207 DROP_BODY_RESPONSES.include?(status) 208 end
drop_content_info?()
click to toggle source
# File lib/sinatra/base.rb 202 def drop_content_info? 203 informational? or drop_body? 204 end