Class: Sinatra::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Sinatra::Request
- Defined in:
- lib/sinatra/base.rb
Overview
The request object. See Rack::Request for more info: rack.rubyforge.org/doc/classes/Rack/Request.html
Instance Method Summary collapse
-
#accept ⇒ Object
Returns an array of acceptable media types for the response.
- #forwarded? ⇒ Boolean
- #idempotent? ⇒ Boolean
- #preferred_type(*types) ⇒ Object (also: #accept?)
- #safe? ⇒ Boolean
Instance Method Details
#accept ⇒ Object
Returns an array of acceptable media types for the response
20 21 22 23 24 25 |
# File 'lib/sinatra/base.rb', line 20 def accept @env['sinatra.accept'] ||= begin entries = @env['HTTP_ACCEPT'].to_s.split(',') entries.map { |e| accept_entry(e) }.sort_by(&:last).map(&:first) end end |
#forwarded? ⇒ Boolean
39 40 41 |
# File 'lib/sinatra/base.rb', line 39 def forwarded? @env.include? "HTTP_X_FORWARDED_HOST" end |
#idempotent? ⇒ Boolean
47 48 49 |
# File 'lib/sinatra/base.rb', line 47 def idempotent? safe? or put? or delete? end |
#preferred_type(*types) ⇒ Object Also known as: accept?
27 28 29 30 31 32 33 34 |
# File 'lib/sinatra/base.rb', line 27 def preferred_type(*types) return accept.first if types.empty? types.flatten! accept.detect do |pattern| type = types.detect { |t| File.fnmatch(pattern, t) } return type if type end end |
#safe? ⇒ Boolean
43 44 45 |
# File 'lib/sinatra/base.rb', line 43 def safe? get? or head? or or trace? end |