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
- #path_info=(value) ⇒ Object
- #preferred_type(*types) ⇒ Object
- #route ⇒ Object
Instance Method Details
#accept ⇒ Object
Returns an array of acceptable media types for the response
16 17 18 19 20 21 |
# File 'lib/sinatra/base.rb', line 16 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
44 45 46 |
# File 'lib/sinatra/base.rb', line 44 def forwarded? @env.include? "HTTP_X_FORWARDED_HOST" end |
#path_info=(value) ⇒ Object
52 53 54 55 |
# File 'lib/sinatra/base.rb', line 52 def path_info=(value) @route = nil super end |
#preferred_type(*types) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/sinatra/base.rb', line 23 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 |
#route ⇒ Object
48 49 50 |
# File 'lib/sinatra/base.rb', line 48 def route @route ||= Rack::Utils.unescape(path_info) end |