class Sinatra::Request

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

Constants

HEADER_PARAM
HEADER_VALUE_WITH_PARAMS

Public Instance Methods

accept() click to toggle source

Returns an array of acceptable media types for the response

# File lib/sinatra/base.rb, line 28
def accept
  @env['sinatra.accept'] ||= begin
    if @env.include? 'HTTP_ACCEPT' and @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
end
accept?(type) click to toggle source
# File lib/sinatra/base.rb, line 39
def accept?(type)
  preferred_type(type).to_s.include?(type)
end
forwarded?() click to toggle source
# File lib/sinatra/base.rb, line 55
def forwarded?
  @env.include? "HTTP_X_FORWARDED_HOST"
end
idempotent?() click to toggle source
# File lib/sinatra/base.rb, line 63
def idempotent?
  safe? or put? or delete? or link? or unlink?
end
params() click to toggle source
Calls superclass method
# File lib/sinatra/base.rb, line 75
def params
  super
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
  raise BadRequest, "Invalid query parameters: #{Rack::Utils.escape_html(e.message)}"
end
preferred_type(*types) click to toggle source
# File lib/sinatra/base.rb, line 43
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
safe?() click to toggle source
# File lib/sinatra/base.rb, line 59
def safe?
  get? or head? or options? or trace?
end