Class: Sinatra::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Sinatra::Request
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb
Overview
The request object. See Rack::Request for more info: rubydoc.info/github/rack/rack/master/Rack/Request
Defined Under Namespace
Classes: AcceptEntry, MimeTypeEntry
Constant Summary collapse
- HEADER_PARAM =
/\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/.freeze
- HEADER_VALUE_WITH_PARAMS =
%r{(?:(?:\w+|\*)/(?:\w+(?:\.|-|\+)?|\*)*)\s*(?:;#{HEADER_PARAM})*}.freeze
Constants inherited from Rack::Request
Rack::Request::ALLOWED_SCHEMES, Rack::Request::SCHEME_WHITELIST
Constants included from Rack::Request::Helpers
Rack::Request::Helpers::DEFAULT_PORTS, Rack::Request::Helpers::FORM_DATA_MEDIA_TYPES, Rack::Request::Helpers::HTTP_X_FORWARDED_FOR, Rack::Request::Helpers::HTTP_X_FORWARDED_HOST, Rack::Request::Helpers::HTTP_X_FORWARDED_PORT, Rack::Request::Helpers::HTTP_X_FORWARDED_PROTO, Rack::Request::Helpers::HTTP_X_FORWARDED_SCHEME, Rack::Request::Helpers::HTTP_X_FORWARDED_SSL, Rack::Request::Helpers::PARSEABLE_DATA_MEDIA_TYPES
Instance Attribute Summary
Attributes included from Rack::Request::Env
Instance Method Summary collapse
-
#accept ⇒ Object
Returns an array of acceptable media types for the response.
- #accept?(type) ⇒ Boolean
- #forwarded? ⇒ Boolean
- #idempotent? ⇒ Boolean
- #link? ⇒ Boolean
- #params ⇒ Object
- #preferred_type(*types) ⇒ Object
- #safe? ⇒ Boolean
- #unlink? ⇒ Boolean
Methods inherited from Rack::Request
#delete_param, #initialize, #update_param
Methods included from Rack::Request::Helpers
#GET, #POST, #[], #[]=, #accept_encoding, #accept_language, #authority, #base_url, #body, #content_charset, #content_length, #content_type, #cookies, #delete?, #delete_param, #form_data?, #forwarded_authority, #forwarded_for, #forwarded_port, #fullpath, #get?, #head?, #host, #host_authority, #host_with_port, #hostname, #ip, #logger, #media_type, #media_type_params, #multithread?, #options?, #parseable_data?, #patch?, #path, #path_info, #path_info=, #port, #post?, #put?, #query_string, #referer, #request_method, #scheme, #script_name, #script_name=, #server_authority, #server_name, #server_port, #session, #session_options, #ssl?, #trace?, #trusted_proxy?, #update_param, #url, #user_agent, #values_at, #xhr?
Methods included from Rack::Request::Env
#add_header, #delete_header, #each_header, #fetch_header, #get_header, #has_header?, #initialize, #initialize_copy, #set_header
Constructor Details
This class inherits a constructor from Rack::Request
Instance Method Details
#accept ⇒ Object
Returns an array of acceptable media types for the response
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 28 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
40 41 42 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 40 def accept?(type) preferred_type(type).to_s.include?(type) end |
#forwarded? ⇒ Boolean
58 59 60 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 58 def forwarded? @env.include? 'HTTP_X_FORWARDED_HOST' end |
#idempotent? ⇒ Boolean
66 67 68 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 66 def idempotent? safe? || put? || delete? || link? || unlink? end |
#link? ⇒ Boolean
70 71 72 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 70 def link? request_method == 'LINK' end |
#params ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 78 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) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 44 def preferred_type(*types) return accept.first if types.empty? types.flatten! return types.first if accept.empty? accept.detect do |accept_header| type = types.detect { |t| MimeTypeEntry.new(t).accepts?(accept_header) } return type if type end end |
#safe? ⇒ Boolean
62 63 64 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 62 def safe? get? || head? || || trace? end |
#unlink? ⇒ Boolean
74 75 76 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 74 def unlink? request_method == 'UNLINK' end |