Class: Carnivore::Http::App::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Carnivore::Http::App::Request
- Includes:
- Zoidberg::SoftShell
- Defined in:
- lib/carnivore-http/app.rb
Overview
Customized request
Instance Attribute Summary collapse
- #response_value ⇒ Response readonly
Instance Method Summary collapse
- #headers ⇒ Smash
- #method ⇒ Symbol
- #remote_addr ⇒ String
-
#respond(code, string_or_args = '') ⇒ TrueClass, FalseClass
Respond to the request.
-
#response(timeout = 5) ⇒ Response
Response to this request.
Instance Attribute Details
#response_value ⇒ Response (readonly)
125 126 127 |
# File 'lib/carnivore-http/app.rb', line 125 def response_value @response_value end |
Instance Method Details
#headers ⇒ Smash
158 159 160 161 162 163 164 |
# File 'lib/carnivore-http/app.rb', line 158 def headers Smash[ env.map do |k,v| k.start_with?('rack.') ? nil : [k.downcase.sub(/^http_/, '').to_sym,v] end.compact ] end |
#method ⇒ Symbol
172 173 174 |
# File 'lib/carnivore-http/app.rb', line 172 def method request_method.to_s.downcase.to_sym end |
#remote_addr ⇒ String
167 168 169 |
# File 'lib/carnivore-http/app.rb', line 167 def remote_addr headers['REMOTE_ADDR'] end |
#respond(code, string_or_args = '') ⇒ TrueClass, FalseClass
Respond to the request
132 133 134 135 136 137 138 |
# File 'lib/carnivore-http/app.rb', line 132 def respond(code, string_or_args='') unless(@response_value) signal(:response, Response.new(code, string_or_args)) else raise 'Response was already set!' end end |
#response(timeout = 5) ⇒ Response
Response to this request
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/carnivore-http/app.rb', line 144 def response(timeout=5) unless(@response_value) begin Timeout.timeout(timeout) do @response_value = wait_for(:response) end rescue Timeout::Error @response_value = Response.new(:internal_server_error, 'Timeout waiting for response') end end @response_value end |