class Sinatra::Request

The request object. See Rack::Request for more info: rack.rubyforge.org/doc/classes/Rack/Request.html

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
23 def accept
24   @env['sinatra.accept'] ||= begin
25     if @env.include? 'HTTP_ACCEPT' and @env['HTTP_ACCEPT'].to_s != ''
26       @env['HTTP_ACCEPT'].to_s.scan(HEADER_VALUE_WITH_PARAMS).
27         map! { |e| AcceptEntry.new(e) }.sort
28     else
29       [AcceptEntry.new('*/*')]
30     end
31   end
32 end
accept?(type) click to toggle source
   # File lib/sinatra/base.rb
34 def accept?(type)
35   preferred_type(type).to_s.include?(type)
36 end
forwarded?() click to toggle source
   # File lib/sinatra/base.rb
51 def forwarded?
52   @env.include? "HTTP_X_FORWARDED_HOST"
53 end
idempotent?() click to toggle source
   # File lib/sinatra/base.rb
59 def idempotent?
60   safe? or put? or delete? or link? or unlink?
61 end
preferred_type(*types) click to toggle source
   # File lib/sinatra/base.rb
38 def preferred_type(*types)
39   accepts = accept # just evaluate once
40   return accepts.first if types.empty?
41   types.flatten!
42   return types.first if accepts.empty?
43   accepts.detect do |pattern|
44     type = types.detect { |t| File.fnmatch(pattern, t) }
45     return type if type
46   end
47 end
safe?() click to toggle source
   # File lib/sinatra/base.rb
55 def safe?
56   get? or head? or options? or trace?
57 end