Class: Ocular::Inputs::HTTP::Input::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Ocular::Inputs::HTTP::Input::Request
- Defined in:
- lib/ocular/inputs/http_input.rb
Defined Under Namespace
Classes: AcceptEntry
Constant Summary collapse
- HEADER_PARAM =
/\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/
- HEADER_VALUE_WITH_PARAMS =
/(?:(?:\w+|\*)\/(?:\w+(?:\.|\-|\+)?|\*)*)\s*(?:;#{HEADER_PARAM})*/
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
- #preferred_type(*types) ⇒ Object
- #safe? ⇒ Boolean
- #unlink? ⇒ Boolean
Instance Method Details
#accept ⇒ Object
Returns an array of acceptable media types for the response
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ocular/inputs/http_input.rb', line 109 def accept @env['sinatra.accept'] ||= begin if @env.include? 'HTTP_ACCEPT' and @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 end |
#accept?(type) ⇒ Boolean
120 121 122 |
# File 'lib/ocular/inputs/http_input.rb', line 120 def accept?(type) preferred_type(type).to_s.include?(type) end |
#forwarded? ⇒ Boolean
137 138 139 |
# File 'lib/ocular/inputs/http_input.rb', line 137 def forwarded? @env.include? "HTTP_X_FORWARDED_HOST" end |
#idempotent? ⇒ Boolean
145 146 147 |
# File 'lib/ocular/inputs/http_input.rb', line 145 def idempotent? safe? or put? or delete? or link? or unlink? end |
#link? ⇒ Boolean
149 150 151 |
# File 'lib/ocular/inputs/http_input.rb', line 149 def link? request_method == "LINK" end |
#preferred_type(*types) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ocular/inputs/http_input.rb', line 124 def preferred_type(*types) accepts = accept # just evaluate once 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
141 142 143 |
# File 'lib/ocular/inputs/http_input.rb', line 141 def safe? get? or head? or or trace? end |
#unlink? ⇒ Boolean
153 154 155 |
# File 'lib/ocular/inputs/http_input.rb', line 153 def unlink? request_method == "UNLINK" end |