Class: Sinatra::Response
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Rack::Response
|
|
Instance Chain:
self,
Rack::Response
|
|
Inherits: |
Rack::Response
|
Defined in: | lib/sinatra/base.rb |
Overview
The response object. See Rack::Response and Rack::Response::Helpers for more info: https://rubydoc.info/github/rack/rack/main/Rack/Response https://rubydoc.info/github/rack/rack/main/Rack/Response/Helpers
Constant Summary
-
DROP_BODY_RESPONSES =
# File 'lib/sinatra/base.rb', line 172[204, 304].freeze
Instance Attribute Summary
- #body=(value) writeonly
- #calculate_content_length? ⇒ Boolean readonly private
- #drop_body? ⇒ Boolean readonly private
- #drop_content_info? ⇒ Boolean readonly private
Instance Method Summary
Instance Attribute Details
#body=(value) (writeonly)
[ GitHub ]# File 'lib/sinatra/base.rb', line 174
def body=(value) value = value.body while Rack::Response === value @body = String === value ? [value.to_str] : value end
#calculate_content_length? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 207
def calculate_content_length? headers['content-type'] && !headers['content-length'] && (Array === body) end
#drop_body? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 215
def drop_body? DROP_BODY_RESPONSES.include?(status) end
#drop_content_info? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 211
def drop_content_info? informational? || drop_body? end
Instance Method Details
#each
[ GitHub ]# File 'lib/sinatra/base.rb', line 179
def each block_given? ? super : enum_for(:each) end
#finish
[ GitHub ]# File 'lib/sinatra/base.rb', line 183
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.map(&:bytesize).reduce(0, :+).to_s end [status, headers, result] end