Class: Sinatra::Request
Overview
Defined Under Namespace
Classes: AcceptEntry
Constant Summary
collapse
/\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/
/(?:(?:\w+|\*)\/(?:\w+(?:\.|\-|\+)?|\*)*)\s*(?:;#{HEADER_PARAM})*/
Rack::Request::DEFAULT_PORTS, Rack::Request::FORM_DATA_MEDIA_TYPES, Rack::Request::PARSEABLE_DATA_MEDIA_TYPES
Instance Attribute Summary
#env
Instance Method Summary
collapse
#GET, #POST, #[], #[]=, #accept_encoding, #base_url, #body, #content_charset, #content_length, #content_type, #cookies, #delete?, #delete_param, #form_data?, #fullpath, #get?, #head?, #host, #host_with_port, #initialize, #ip, #logger, #media_type, #media_type_params, #options?, #params, #parseable_data?, #patch?, #path, #path_info, #path_info=, #port, #post?, #put?, #query_string, #referer, #request_method, #scheme, #script_name, #script_name=, #session, #session_options, #ssl?, #trace?, #trusted_proxy?, #update_param, #url, #user_agent, #values_at, #xhr?
Constructor Details
This class inherits a constructor from Rack::Request
Instance Method Details
Returns an array of acceptable media types for the response
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 23
def accept
@env['sinatra.accept'] ||= begin
if @env.include? 'HTTP_ACCEPT' and @env['HTTP_ACCEPT'].to_s != ''
@env['HTTP_ACCEPT'].to_s.scan().
map! { |e| AcceptEntry.new(e) }.sort
else
[AcceptEntry.new('*/*')]
end
end
end
|
#accept?(type) ⇒ Boolean
34
35
36
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 34
def accept?(type)
preferred_type(type).include?(type)
end
|
#forwarded? ⇒ Boolean
51
52
53
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 51
def forwarded?
@env.include? "HTTP_X_FORWARDED_HOST"
end
|
#idempotent? ⇒ Boolean
59
60
61
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 59
def idempotent?
safe? or put? or delete? or link? or unlink?
end
|
#link? ⇒ Boolean
63
64
65
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 63
def link?
request_method == "LINK"
end
|
#preferred_type(*types) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 38
def preferred_type(*types)
accepts = accept
return accepts.first if types.empty?
types.flatten!
return types.first if accepts.empty?
accepts.detect do |pattern|
type = types.detect { |t| File.fnmatch(pattern, t) }
return type if type
end
end
|
#safe? ⇒ Boolean
55
56
57
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 55
def safe?
get? or head? or options? or trace?
end
|
#unlink? ⇒ Boolean
67
68
69
|
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 67
def unlink?
request_method == "UNLINK"
end
|