Class: Sinatra::Request
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Rack::Request
|
|
Instance Chain:
self,
Rack::Request
|
|
Inherits: |
Rack::Request
|
Defined in: | lib/sinatra/base.rb |
Overview
The request object. See Rack::Request for more info: https://rubydoc.info/github/rack/rack/main/Rack/Request
Constant Summary
-
HEADER_PARAM =
# File 'lib/sinatra/base.rb', line 32/\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/.freeze
-
HEADER_VALUE_WITH_PARAMS =
# File 'lib/sinatra/base.rb', line 33%r{(?:(?:\w+|\*)/(?:\w+(?:\.|-|\+)?|\*)*)\s*(?:;#{HEADER_PARAM})*}.freeze
Instance Attribute Summary
- #forwarded? ⇒ Boolean readonly
- #idempotent? ⇒ Boolean readonly
- #link? ⇒ Boolean readonly
- #safe? ⇒ Boolean readonly
- #unlink? ⇒ Boolean readonly
Instance Method Summary
-
#accept
Returns an array of acceptable media types for the response.
- #accept?(type) ⇒ Boolean
- #params
- #preferred_type(*types)
- #secure?
Instance Attribute Details
#forwarded? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 66
def forwarded? ! .nil? end
#idempotent? ⇒ Boolean
(readonly)
[ GitHub ]
#link? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 78
def link? request_method == 'LINK' end
#safe? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 70
def safe? get? || head? || || trace? end
#unlink? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/sinatra/base.rb', line 82
def unlink? request_method == 'UNLINK' end
Instance Method Details
#accept
Returns an array of acceptable media types for the response
# File 'lib/sinatra/base.rb', line 36
def accept @env['sinatra.accept'] ||= if @env.include?('HTTP_ACCEPT') && (@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
#accept?(type) ⇒ Boolean
# File 'lib/sinatra/base.rb', line 48
def accept?(type) preferred_type(type).to_s.include?(type) end
#params
[ GitHub ]# File 'lib/sinatra/base.rb', line 86
def params super rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise BadRequest, "Invalid query parameters: #{Rack::Utils.escape_html(e. )}" rescue EOFError => e raise BadRequest, "Invalid multipart/form-data: #{Rack::Utils.escape_html(e. )}" end
#preferred_type(*types)
[ GitHub ]#secure?
[ GitHub ]# File 'lib/sinatra/base.rb', line 64
alias secure? ssl?