Class: Sinatra::Response

Inherits:
Rack::Response
  • Object
show all
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 collapse

DROP_BODY_RESPONSES =
[204, 304].freeze

Instance Method Summary collapse

Instance Method Details

#body=(value) ⇒ Object



174
175
176
177
# 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

#eachObject



179
180
181
# File 'lib/sinatra/base.rb', line 179

def each
  block_given? ? super : enum_for(:each)
end

#finishObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/sinatra/base.rb', line 183

def finish
  result = body

  if 
    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