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
30 def accept
31   @env['sinatra.accept'] ||= begin
32     if @env.include? 'HTTP_ACCEPT' and @env['HTTP_ACCEPT'].to_s != ''
33       @env['HTTP_ACCEPT'].to_s.scan(HEADER_VALUE_WITH_PARAMS).
34         map! { |e| AcceptEntry.new(e) }.sort
35     else
36       [AcceptEntry.new('*/*')]
37     end
38   end
39 end
accept?(type) click to toggle source
   # File lib/sinatra/base.rb
41 def accept?(type)
42   preferred_type(type).to_s.include?(type)
43 end
forwarded?() click to toggle source
   # File lib/sinatra/base.rb
58 def forwarded?
59   @env.include? "HTTP_X_FORWARDED_HOST"
60 end
idempotent?() click to toggle source
   # File lib/sinatra/base.rb
66 def idempotent?
67   safe? or put? or delete? or link? or unlink?
68 end
params() click to toggle source
Calls superclass method
   # File lib/sinatra/base.rb
78 def params
79   super
80 rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
81   raise BadRequest, "Invalid query parameters: #{Rack::Utils.escape_html(e.message)}"
82 end
preferred_type(*types) click to toggle source
   # File lib/sinatra/base.rb
45 def preferred_type(*types)
46   accepts = accept # just evaluate once
47   return accepts.first if types.empty?
48   types.flatten!
49   return types.first if accepts.empty?
50   accepts.detect do |pattern|
51     type = types.detect { |t| File.fnmatch(pattern, t) }
52     return type if type
53   end
54 end
safe?() click to toggle source
   # File lib/sinatra/base.rb
62 def safe?
63   get? or head? or options? or trace?
64 end