Class: Sinatra::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Sinatra::Response
- Defined in:
- lib/sinatra/base.rb
Overview
The response object. See Rack::Response and Rack::ResponseHelpers for more info: rack.rubyforge.org/doc/classes/Rack/Response.html rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
Instance Method Summary collapse
Instance Method Details
#body=(value) ⇒ Object
66 67 68 69 |
# File 'lib/sinatra/base.rb', line 66 def body=(value) value = value.body while Rack::Response === value @body = String === value ? [value.to_str] : value end |
#each ⇒ Object
71 72 73 |
# File 'lib/sinatra/base.rb', line 71 def each block_given? ? super : enum_for(:each) end |
#finish ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sinatra/base.rb', line 75 def finish if status.to_i / 100 == 1 headers.delete "Content-Length" headers.delete "Content-Type" elsif Array === body and not [204, 304].include?(status.to_i) # 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 # Rack::Response#finish sometimes returns self as response body. We don't want that. status, headers, result = super result = body if result == self [status, headers, result] end |