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 24
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 35
def accept?(type)
  preferred_type(type).to_s.include?(type)
end
forwarded?() click to toggle source
# File lib/sinatra/base.rb, line 52
def forwarded?
  @env.include? "HTTP_X_FORWARDED_HOST"
end
idempotent?() click to toggle source
# File lib/sinatra/base.rb, line 60
def idempotent?
  safe? or put? or delete? or link? or unlink?
end
preferred_type(*types) click to toggle source
# File lib/sinatra/base.rb, line 39
def preferred_type(*types)
  accepts = accept # just evaluate once
  return accepts.first if types.empty?
  types.flatten!
  return types.first if accepts.empty?
  accepts.detect do |pattern|
    type = types.detect { |t| File.fnmatch(pattern, t) }
    return type if type
  end
end
safe?() click to toggle source
# File lib/sinatra/base.rb, line 56
def safe?
  get? or head? or options? or trace?
end