Class: Sinatra::Response

Inherits:
Rack::Response show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb

Overview

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

Constant Summary collapse

DROP_BODY_RESPONSES =
[204, 304].freeze

Constants inherited from Rack::Response

Rack::Response::CHUNKED, Rack::Response::STATUS_WITH_NO_ENTITY_BODY

Instance Attribute Summary

Attributes inherited from Rack::Response

#body, #headers, #length, #status

Instance Method Summary collapse

Methods inherited from Rack::Response

[], #chunked?, #close, #delete_header, #empty?, #get_header, #has_header?, #initialize, #redirect, #set_header, #write

Methods included from Rack::Response::Helpers

#accepted?, #add_header, #bad_request?, #cache!, #cache_control, #cache_control=, #client_error?, #content_length, #content_type, #content_type=, #created?, #delete_cookie, #do_not_cache!, #etag, #etag=, #forbidden?, #include?, #informational?, #invalid?, #location, #location=, #media_type, #media_type_params, #method_not_allowed?, #moved_permanently?, #no_content?, #not_found?, #ok?, #precondition_failed?, #redirect?, #redirection?, #server_error?, #set_cookie, #set_cookie_header, #set_cookie_header=, #successful?, #unauthorized?, #unprocessable?

Constructor Details

This class inherits a constructor from Rack::Response

Instance Method Details

#body=(value) ⇒ Object



166
167
168
169
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 166

def body=(value)
  value = value.body while Rack::Response === value
  @body = String === value ? [value.to_str] : value
end

#eachObject



171
172
173
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 171

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

#finishObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 175

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