123456789_123456789_123456789_123456789_123456789_

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
  • Object
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

Instance Attribute Summary

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 
  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 
    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