123456789_123456789_123456789_123456789_123456789_

Class: Sinatra::Request

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Rack::Request
Instance Chain:
self, Rack::Request
Inherits: Rack::Request
  • Object
Defined in: lib/sinatra/base.rb

Overview

The request object. See Rack::Request for more info: https://rubydoc.info/github/rack/rack/main/Rack/Request

Constant Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#forwarded?Boolean (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 66

def forwarded?
  !forwarded_authority.nil?
end

#idempotent?Boolean (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 74

def idempotent?
  safe? || put? || delete? || link? || unlink?
end

#link?Boolean (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 78

def link?
  request_method == 'LINK'
end

#safe?Boolean (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 70

def safe?
  get? || head? || options? || trace?
end

#unlink?Boolean (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 82

def unlink?
  request_method == 'UNLINK'
end

Instance Method Details

#accept

Returns an array of acceptable media types for the response

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 36

def accept
  @env['sinatra.accept'] ||= if @env.include?('HTTP_ACCEPT') && (@env['HTTP_ACCEPT'].to_s != '')
                               @env['HTTP_ACCEPT']
                                 .to_s
                                 .scan(HEADER_VALUE_WITH_PARAMS)
                                 .map! { |e| AcceptEntry.new(e) }
                                 .sort
                             else
                               [AcceptEntry.new('*/*')]
                             end
end

#accept?(type) ⇒ Boolean

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 48

def accept?(type)
  preferred_type(type).to_s.include?(type)
end

#params

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 86

def params
  super
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
  raise BadRequest, "Invalid query parameters: #{Rack::Utils.escape_html(e.message)}"
rescue EOFError => e
  raise BadRequest, "Invalid multipart/form-data: #{Rack::Utils.escape_html(e.message)}"
end

#preferred_type(*types)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 52

def preferred_type(*types)
  return accept.first if types.empty?

  types.flatten!
  return types.first if accept.empty?

  accept.detect do |accept_header|
    type = types.detect { |t| MimeTypeEntry.new(t).accepts?(accept_header) }
    return type if type
  end
end

#secure?

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 64

alias secure? ssl?